Created
January 24, 2018 18:42
-
-
Save pomle/69232b759ec69d74543d876f9d9aab69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FAIL src/store/session/__tests__/session.test.js | |
Session state | |
reducer | |
✓ produces an initial state (1ms) | |
when auth set | |
✕ stores token (1ms) | |
✕ stores expiry date (1ms) | |
✕ stores refresh token | |
when token set | |
✓ stores token in state (1ms) | |
✓ applies token to albumAPI | |
✓ applies token to artistAPI | |
✓ applies token to playbackAPI (1ms) | |
✓ applies token to playlistAPI | |
✓ applies token to searchAPI | |
✓ applies token to trackAPI | |
● Session state › reducer › when auth set › stores token | |
ReferenceError: setAuth is not defined | |
at Object.<anonymous> (src/store/session/__tests__/session.test.js:27:34) | |
at new Promise (<anonymous>) | |
at <anonymous> | |
at process._tickCallback (internal/process/next_tick.js:188:7) | |
● Session state › reducer › when auth set › stores token | |
expect(received).toBe(expected) | |
Expected value to be (using ===): | |
"98m12vmu54u10v9824jum19284j" | |
Received: | |
null | |
Difference: | |
Comparing two different types of values. Expected string but received null. | |
at Object.<anonymous> (src/store/session/__tests__/session.test.js:31:31) | |
at new Promise (<anonymous>) | |
at <anonymous> | |
at process._tickCallback (internal/process/next_tick.js:188:7) | |
● Session state › reducer › when auth set › stores expiry date | |
ReferenceError: setAuth is not defined | |
at Object.<anonymous> (src/store/session/__tests__/session.test.js:27:34) | |
at new Promise (<anonymous>) | |
at <anonymous> | |
at process._tickCallback (internal/process/next_tick.js:188:7) | |
● Session state › reducer › when auth set › stores expiry date | |
expect(received).toBe(expected) | |
Expected value to be (using ===): | |
1516818786148 | |
Received: | |
null | |
Difference: |
This file contains hidden or 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
import {Map, List} from 'immutable'; | |
import { reducer, setToken } from '..'; | |
describe('Session state', () => { | |
describe('reducer', () => { | |
let session; | |
beforeEach(() => { | |
session = reducer(); | |
}); | |
it('produces an initial state', () => { | |
expect(session.deviceId).toBe(null); | |
expect(session.token).toBe(null); | |
expect(session.expiresAt).toBe(null); | |
expect(session.refreshToken).toBe(null); | |
}); | |
describe('when auth set', () => { | |
const FAKE_TOKEN = '98m12vmu54u10v9824jum19284j'; | |
const FAKE_REFRESH_TOKEN = '1921v012m41281259129'; | |
const FAKE_EXPIRES_IN = 3600; | |
beforeEach(() => { | |
Date.now = jest.fn().mockReturnValue(1516818786148); | |
session = reducer(session, setAuth(FAKE_TOKEN, 3600, FAKE_REFRESH_TOKEN)); | |
}); | |
it('stores token', () => { | |
expect(session.token).toBe(FAKE_TOKEN); | |
}); | |
it('stores expiry date', () => { | |
expect(session.expiresAt).toBe(1516818786148); | |
}); | |
it('stores refresh token', () => { | |
expect(session.refreshToken).toBe(FAKE_REFRESH_TOKEN); | |
}); | |
}); | |
describe('when token set', () => { | |
const FAKE_TOKEN = '98m12vmu54u10v9824jum19284j'; | |
beforeEach(() => { | |
session = reducer(session, setToken(FAKE_TOKEN)); | |
}); | |
it('stores token in state', () => { | |
expect(session.token).toBe(FAKE_TOKEN); | |
}); | |
[ | |
'albumAPI', | |
'artistAPI', | |
'playbackAPI', | |
'playlistAPI', | |
'searchAPI', | |
'trackAPI', | |
].forEach(name => { | |
it(`applies token to ${name}`, () => { | |
const api = session[name]; | |
expect(api.token).toBe(FAKE_TOKEN); | |
}); | |
}); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment