feat: signal server tag

This commit is contained in:
2026-06-05 06:16:02 +02:00
parent 6865147e8f
commit bf4e6891d1
69 changed files with 2808 additions and 1269 deletions
@@ -0,0 +1,39 @@
import { firstValueFrom, of } from 'rxjs';
import {
describe,
expect,
it
} from 'vitest';
import { UsersActions } from '../../../../store/users/users.actions';
import { waitForAuthenticationOutcome } from './auth-navigation.rules';
describe('waitForAuthenticationOutcome', () => {
it('resolves when authentication storage preparation succeeds', async () => {
const user = {
id: 'user-1',
oderId: 'user-1',
username: 'alice',
displayName: 'Alice',
status: 'online' as const,
role: 'member' as const,
joinedAt: 1
};
const outcome = await firstValueFrom(waitForAuthenticationOutcome(of(
UsersActions.setCurrentUser({ user })
)));
expect(outcome).toEqual({ kind: 'success', user });
});
it('resolves with a failure when authentication storage preparation fails', async () => {
const outcome = await firstValueFrom(waitForAuthenticationOutcome(of(
UsersActions.loadCurrentUserFailure({ error: 'Failed to prepare local user state.' })
)));
expect(outcome).toEqual({
kind: 'failure',
error: 'Failed to prepare local user state.'
});
});
});
@@ -0,0 +1,45 @@
import {
filter,
map,
Observable,
take
} from 'rxjs';
import { UsersActions } from '../../../../store/users/users.actions';
import type { User } from '../../../../shared-kernel';
export type AuthenticationOutcome =
| { kind: 'success'; user: User }
| { kind: 'failure'; error: string };
export function waitForAuthenticationOutcome(
actions$: Observable<{ type: string; user?: User; error?: string }>
): Observable<AuthenticationOutcome> {
return actions$.pipe(
filter((action) =>
action.type === UsersActions.setCurrentUser.type
|| action.type === UsersActions.loadCurrentUserFailure.type
),
take(1),
map((action) => {
if (action.type === UsersActions.loadCurrentUserFailure.type) {
return {
kind: 'failure' as const,
error: action.error || 'Authentication failed'
};
}
if (!action.user) {
return {
kind: 'failure' as const,
error: 'Authentication failed'
};
}
return {
kind: 'success' as const,
user: action.user
};
})
);
}