* Move visibility param from redux store to local state * use func for parsing location.search * Remove bad wrapper * we already have wrapper with NODE_ID on page and we shouldn't another one with the same id on page * move common part of markup to level up * Tinny refac of setSorting * add dummy types for pollyfils also, a bit rewrited way to resolve imports * Move sort flag to local store Because we don't need to share this param between diffrent parts of interface * Add action creators * move action to action creators * Remove unused functions * Merge in conditions in one * One way for export API methods * add default tags * Rewrited changing read only mode * removed unused function * set sort changes * always send sort from store * rollback if sort don't work * constanst * add typing * shorten export * remove double define of host
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
import * as api from '@app/common/api';
|
|
import { User } from '@app/common/types';
|
|
|
|
import { fetchUser, logIn, logout } from './actions';
|
|
import { user } from './reducers';
|
|
import { USER_SET } from './types';
|
|
|
|
jest.mock('@app/common/api');
|
|
|
|
afterEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
describe('user', () => {
|
|
it('should return null by default', () => {
|
|
const action = { type: 'OTHER' };
|
|
const newState = user(null, action as any);
|
|
expect(newState).toEqual(null);
|
|
});
|
|
|
|
it('should set state of user on fetchUser', async () => {
|
|
(api.getUser as any).mockImplementation(
|
|
async (): Promise<User> =>
|
|
({
|
|
id: 'john',
|
|
name: 'John',
|
|
admin: true,
|
|
} as User)
|
|
);
|
|
const dispatch = jest.fn();
|
|
const getState = jest.fn();
|
|
await fetchUser()(dispatch, getState, undefined);
|
|
expect(dispatch).toBeCalledWith({
|
|
type: USER_SET,
|
|
user: {
|
|
id: 'john',
|
|
name: 'John',
|
|
admin: true,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should set state of user on logIn', async () => {
|
|
(api.logIn as any).mockImplementation(
|
|
async (): Promise<User> =>
|
|
({
|
|
id: 'john',
|
|
name: 'John',
|
|
admin: true,
|
|
} as User)
|
|
);
|
|
const dispatch = jest.fn();
|
|
const getState = jest.fn();
|
|
await logIn({ name: 'google' })(dispatch, getState, undefined);
|
|
expect(dispatch).toBeCalledWith({
|
|
type: USER_SET,
|
|
user: {
|
|
id: 'john',
|
|
name: 'John',
|
|
admin: true,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should NOT set state of user on failed logIn', async () => {
|
|
(api.logIn as any).mockImplementation(
|
|
async (): Promise<User> => {
|
|
throw new Error('Unauthorized');
|
|
}
|
|
);
|
|
const dispatch = jest.fn();
|
|
const getState = jest.fn();
|
|
await logIn({ name: 'google' })(dispatch, getState, undefined).catch(() => {});
|
|
expect(dispatch).not.toBeCalled();
|
|
});
|
|
|
|
it('should unset user on logOut', async () => {
|
|
(api.logOut as any).mockImplementation(async (): Promise<void> => {});
|
|
const dispatch = jest.fn();
|
|
const getState = jest.fn();
|
|
await logout()(dispatch, getState, undefined);
|
|
expect(dispatch).toBeCalledWith({
|
|
type: USER_SET,
|
|
user: null,
|
|
});
|
|
});
|
|
});
|