Skip to content

Commit

Permalink
test: add tests for MixerStore
Browse files Browse the repository at this point in the history
  • Loading branch information
fmalcher committed Dec 30, 2024
1 parent 76bfec4 commit 62e540e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions packages/mixer-connection/src/lib/state/mixer-store.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { firstValueFrom, Subject } from 'rxjs';
import { MixerConnection } from '../mixer-connection';
import { MixerStore } from './mixer-store';

describe('Mixer Store', () => {
let conn: { allMessages$: Subject<string> };
let mixerStore: MixerStore;

function sendMessage(message: string): void {
conn.allMessages$.next(message);
}

beforeEach(() => {
conn = {
allMessages$: new Subject<string>(),
};

mixerStore = new MixerStore(conn as unknown as MixerConnection);
});

it('should reduce channel sync state', async () => {
sendMessage('BMSG^SYNC^mySyncId^5');
sendMessage('BMSG^SYNC^mySyncId^6');
sendMessage('BMSG^SYNC^mySyncId^10');
expect(await firstValueFrom(mixerStore.syncState$)).toEqual({ mySyncId: 10 });

sendMessage('BMSG^SYNC^SYNC_ID^8');
sendMessage('BMSG^SYNC^SYNC_ID^20');
expect(await firstValueFrom(mixerStore.syncState$)).toEqual({ mySyncId: 10, SYNC_ID: 20 });

sendMessage('BMSG^SYNC^mySyncId^44');
sendMessage('BMSG^SYNC^anotherSyncId^11');
expect(await firstValueFrom(mixerStore.syncState$)).toEqual({
mySyncId: 44,
SYNC_ID: 20,
anotherSyncId: 11,
});
});

describe('state$', () => {
it('should reduce SETD/SETS messages to state', async () => {
sendMessage('SETD^i.3.mute^0');
sendMessage('SETD^i.4.mute^1');
sendMessage('SETS^i.10.name^channelname');
expect(await firstValueFrom(mixerStore.state$)).toEqual({
'i.3.mute': 0,
'i.4.mute': 1,
'i.10.name': 'channelname',
});

sendMessage('SETS^i.10.name^anothername');
sendMessage('SETD^i.3.mute^1');
expect(await firstValueFrom(mixerStore.state$)).toEqual({
'i.3.mute': 1,
'i.4.mute': 1,
'i.10.name': 'anothername',
});
});

it('should ignore messages other than SETD or SETS', async () => {
sendMessage('SETD^abc^def');

sendMessage('FOO^bar^baz');
sendMessage('XYZ^xyz^xyz');
expect(await firstValueFrom(mixerStore.state$)).toEqual({ abc: 'def' });
});
});
});

0 comments on commit 62e540e

Please sign in to comment.