|
1 | 1 | import { TokenSourceResponse } from '@livekit/protocol'; |
2 | 2 | import { describe, expect, it } from 'vitest'; |
3 | | -import { decodeTokenPayload, isResponseTokenValid } from './utils'; |
| 3 | +import { areTokenSourceFetchOptionsEqual, decodeTokenPayload, isResponseTokenValid } from './utils'; |
4 | 4 |
|
5 | 5 | // Test JWTs created for test purposes only. |
6 | 6 | // None of these actually auth against anything. |
@@ -61,3 +61,37 @@ describe('decodeTokenPayload', () => { |
61 | 61 | expect(payload.roomConfig?.agents![0].metadata).toBe('test agent metadata'); |
62 | 62 | }); |
63 | 63 | }); |
| 64 | + |
| 65 | +describe('areTokenSourceFetchOptionsEqual', () => { |
| 66 | + it('should ensure two identical options objects of different references are equal', () => { |
| 67 | + expect( |
| 68 | + areTokenSourceFetchOptionsEqual( |
| 69 | + { agentName: 'my agent name' }, |
| 70 | + { agentName: 'my agent name' }, |
| 71 | + ), |
| 72 | + ).to.equal(true); |
| 73 | + }); |
| 74 | + it('should ensure two empty options objects are equal', () => { |
| 75 | + expect(areTokenSourceFetchOptionsEqual({}, {})).to.equal(true); |
| 76 | + }); |
| 77 | + it('should ensure empty on the left and filled on the right are not equal', () => { |
| 78 | + expect(areTokenSourceFetchOptionsEqual({}, { agentName: 'my agent name' })).to.equal(false); |
| 79 | + }); |
| 80 | + it('should ensure filled on the left and empty on the right are not equal', () => { |
| 81 | + expect(areTokenSourceFetchOptionsEqual({ agentName: 'my agent name' }, {})).to.equal(false); |
| 82 | + }); |
| 83 | + it('should ensure objects with different keys/values are not equal', () => { |
| 84 | + expect( |
| 85 | + areTokenSourceFetchOptionsEqual( |
| 86 | + { agentName: 'foo' }, |
| 87 | + { agentName: 'bar', agentMetadata: 'baz' }, |
| 88 | + ), |
| 89 | + ).to.equal(false); |
| 90 | + expect( |
| 91 | + areTokenSourceFetchOptionsEqual( |
| 92 | + { agentName: 'bar', agentMetadata: 'baz' }, |
| 93 | + { agentName: 'foo' }, |
| 94 | + ), |
| 95 | + ).to.equal(false); |
| 96 | + }); |
| 97 | +}); |
0 commit comments