Newer
Older

OZGCloud
committed
import { ApiError, createStateResource } from '@goofy-client/tech-shared';
import { Action } from '@ngrx/store';
import { createUserProfileResource } from 'libs/user-profile-shared/test/user-profile';
import { createUserSettings, createUserSettingsResource } from 'libs/user-settings-shared/test/user-settings';
import { createApiError } from '../../../../tech-shared/test/error';

OZGCloud
committed
import { UserSettingsResource } from '../user-settings.model';
import * as UserSettingsActions from './user-settings.actions';

OZGCloud
committed
import { initialUserSettingsState, userSettingsReducer, UserSettingsState } from './user-settings.reducer';

OZGCloud
committed
describe('User Settings Reducer', () => {

OZGCloud
committed
describe('unknown action', () => {

OZGCloud
committed
it('should return current state', () => {

OZGCloud
committed
const action: Action = {} as Action;

OZGCloud
committed
const result = userSettingsReducer(initialUserSettingsState, action);
expect(result).toBe(initialUserSettingsState);
})
})
describe('loadUserSettings', () => {
describe('on "loadUserSettings" action', () => {
it('should set loading to true', () => {

OZGCloud
committed
const action: Action = UserSettingsActions.loadUserSettings({ currentUser: createUserProfileResource() });

OZGCloud
committed
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);
expect(state.userSettings.loading).toBeTruthy();
})
})
})
describe('on "loadUserSettingsSuccess"', () => {

OZGCloud
committed
const userSettings: UserSettingsResource = createUserSettingsResource();
const action: Action = UserSettingsActions.loadUserSettingsSuccess({ userSettings });
it('should set loaded resource', () => {

OZGCloud
committed
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);
expect(state.userSettings).toEqual(createStateResource(userSettings));
})
it('should has property "notificationsSendFor"', () => {

OZGCloud
committed
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);
expect(state.userSettings).toHaveProperty('resource.notificationsSendFor');
})
})
describe('on "loadUserSettingsFailure"', () => {
it('should set apiError', () => {
const apiError: ApiError = createApiError();

OZGCloud
committed
const action: Action = UserSettingsActions.loadUserSettingsFailure({ apiError });

OZGCloud
committed
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);
expect(state.userSettings.error).toStrictEqual(apiError);
})
describe('setUserSettings', () => {

OZGCloud
committed
describe('on "setUserSettings" action', () => {

OZGCloud
committed
it('should set state resource to loading', () => {

OZGCloud
committed
const action: Action = UserSettingsActions.setUserSettings({ userSettings: createUserSettings() });
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);
expect(state.userSettings.loading).toBeTruthy();
})
})
describe('on "setUserSettingsSuccess" action', () => {

OZGCloud
committed
const userSettingsResource: UserSettingsResource = createUserSettingsResource();
const action: Action = UserSettingsActions.setUserSettingsSuccess({ userSettings: userSettingsResource });

OZGCloud
committed
it('should set loaded resource', () => {
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);

OZGCloud
committed
expect(state.userSettings).toEqual(createStateResource(userSettingsResource));
})
})
describe('on "setUserSettingsFailure" action', () => {

OZGCloud
committed
it('should set API Error', () => {

OZGCloud
committed
const apiError: ApiError = createApiError();
const action: Action = UserSettingsActions.setUserSettingsFailure({ apiError });

OZGCloud
committed
const state: UserSettingsState = userSettingsReducer(initialUserSettingsState, action);
expect(state.userSettings.error).toStrictEqual(apiError);