This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
194d05b
commit 3f81920
Showing
11 changed files
with
166 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/auth/session/storage/__tests__/session-test-utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {Session} from '../../session'; | ||
|
||
import {sessionArraysEqual} from './session-test-utils'; | ||
|
||
describe('test sessionArraysEqual', () => { | ||
it('returns true for two identically ordered arrays', () => { | ||
const sessionsExpected = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', true), | ||
]; | ||
const sessionsToCompare = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', true), | ||
]; | ||
|
||
expect(sessionArraysEqual(sessionsToCompare, sessionsExpected)).toBe(true); | ||
}); | ||
|
||
it('returns true for two arrays with same content but out of order', () => { | ||
const sessionsExpected = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', true), | ||
]; | ||
const sessionsToCompare = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', true), | ||
]; | ||
|
||
expect(sessionArraysEqual(sessionsToCompare, sessionsExpected)).toBe(true); | ||
}); | ||
|
||
it('returns false for two arrays not the same size', () => { | ||
const sessionsExpected = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
]; | ||
const sessionsToCompare = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', true), | ||
]; | ||
|
||
expect(sessionArraysEqual(sessionsToCompare, sessionsExpected)).toBe(false); | ||
}); | ||
|
||
it('returns false for two arrays of the same size but different content', () => { | ||
const sessionsExpected = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', true), | ||
]; | ||
let sessionsToCompare = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_5', 'shop3-sessions', 'state', true), | ||
]; | ||
|
||
expect(sessionArraysEqual(sessionsToCompare, sessionsExpected)).toBe(false); | ||
|
||
sessionsToCompare = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop4-sessions', 'state', true), | ||
]; | ||
|
||
expect(sessionArraysEqual(sessionsToCompare, sessionsExpected)).toBe(false); | ||
|
||
sessionsToCompare = [ | ||
new Session('test_sessions_1', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_3', 'shop1-sessions', 'state', true), | ||
new Session('test_sessions_2', 'shop2-sessions', 'state', true), | ||
new Session('test_sessions_4', 'shop3-sessions', 'state', false), | ||
]; | ||
|
||
expect(sessionArraysEqual(sessionsToCompare, sessionsExpected)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {sessionEqual} from '../../session-utils'; | ||
import {SessionInterface} from '../../types'; | ||
|
||
// compare two arrays of sessions that should contain | ||
// the same sessions but may be in a different order | ||
export function sessionArraysEqual( | ||
sessionArray1: SessionInterface[], | ||
sessionArray2: SessionInterface[], | ||
): boolean { | ||
if (sessionArray1.length !== sessionArray2.length) { | ||
return false; | ||
} | ||
|
||
for (const session1 of sessionArray1) { | ||
let found = false; | ||
for (const session2 of sessionArray2) { | ||
if (sessionEqual(session1, session2)) { | ||
found = true; | ||
continue; | ||
} | ||
} | ||
if (!found) return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.