Download pool/shard001/JavaScript/0006018_routes.test.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/JavaScript/0006018_routes.test.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/JavaScript/0006018_routes.test.js
-
curl -L -o 0006018_routes.test.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/JavaScript/0006018_routes.test.js
2.39 kB
| import test from 'ava'; | |
| import * as I from 'immutable'; | |
| import * as td from 'testdouble'; | |
| import { ensureLoggedIn, login } from './routes'; | |
| import { push } from 'react-router-redux'; | |
| import * as AuthActionCreators from '../action-creators/auth'; | |
| test('"ensureLoggedIn" should redirect the user to "/", if the token does not exist', () => { | |
| const session = I.Map({}); | |
| const dispatch = td.function(); | |
| const store = { | |
| getState: () => ({ session }), | |
| dispatch, | |
| }; | |
| ensureLoggedIn(store); | |
| td.verify(dispatch(push('/'))); | |
| }); | |
| test('"ensureLoggedIn" should do no redirects, if the token exists', (assert) => { | |
| const session = I.Map({ token: '123' }); | |
| const dispatch = td.function(); | |
| const store = { | |
| getState: () => ({ session }), | |
| dispatch, | |
| }; | |
| ensureLoggedIn(store); | |
| assert.throws(() => td.verify(dispatch(td.matchers.anything()))); | |
| }); | |
| test('"login" should save user token and name, if they exist in the querystring', () => { | |
| const accessToken = '1234'; | |
| const firstName = 'John'; | |
| const lastName = 'Doe'; | |
| const displayName = `${firstName} ${lastName}`; | |
| const state = { | |
| routing: { | |
| locationBeforeTransitions: { | |
| query: { | |
| access_token: accessToken, | |
| display_name: displayName, | |
| }, | |
| }, | |
| }, | |
| }; | |
| const store = { | |
| getState: () => state, | |
| dispatch: td.function(), | |
| }; | |
| login(store); | |
| td.verify(store.dispatch(AuthActionCreators.loginUser({ firstName, lastName }, accessToken))); | |
| }); | |
| test('"login" should redirect to "/", if token doesn\'t exist in querystring', () => { | |
| const firstName = 'John'; | |
| const lastName = 'Doe'; | |
| const displayName = `${firstName} ${lastName}`; | |
| const state = { | |
| routing: { | |
| locationBeforeTransitions: { | |
| query: { | |
| display_name: displayName, | |
| }, | |
| }, | |
| }, | |
| }; | |
| const store = { | |
| getState: () => state, | |
| dispatch: td.function(), | |
| }; | |
| login(store); | |
| td.verify(store.dispatch(push('/'))); | |
| }); | |
| test('"login" should redirect to "/", if "displayName" doesn\'t exist in querystring', () => { | |
| const accessToken = '123'; | |
| const state = { | |
| routing: { | |
| locationBeforeTransitions: { | |
| query: { | |
| access_token: accessToken, | |
| }, | |
| }, | |
| }, | |
| }; | |
| const store = { | |
| getState: () => state, | |
| dispatch: td.function(), | |
| }; | |
| login(store); | |
| td.verify(store.dispatch(push('/'))); | |
| }); | |