test(core): add session state test

pull/1918/head
mehmet-erim 5 years ago
parent e07765c7be
commit 2770ceefd5

@ -92,6 +92,7 @@
"prettier --write",
"tslint --fix",
"git add"
]
],
"dist/*": []
}
}

@ -35,7 +35,7 @@ export class SessionState {
}
@Action(SetTenant)
setTenantId({ patchState }: StateContext<Session.State>, { payload }: SetTenant) {
setTenant({ patchState }: StateContext<Session.State>, { payload }: SetTenant) {
patchState({
tenant: payload,
});

@ -109,7 +109,7 @@ export const CONFIG_STATE_DATA = {
},
} as Config.State;
describe('ConfigService', () => {
describe('ConfigState', () => {
let spectator: SpectatorService<ConfigService>;
let store: SpyObject<Store>;
let service: ConfigService;

@ -0,0 +1,70 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { Session } from '../models/session';
import { LocalizationService } from '../services';
import { SessionState } from '../states';
import { GetAppConfiguration } from '../actions/config.actions';
import { of } from 'rxjs';
export class DummyClass {}
export const SESSION_STATE_DATA = {
language: 'tr',
tenant: { id: 'd5692aef-2ac6-49cd-9f3e-394c0bd4f8b3', name: 'Test' },
} as Session.State;
describe('SessionState', () => {
let spectator: SpectatorService<DummyClass>;
let state: SessionState;
const createService = createServiceFactory({
service: DummyClass,
mocks: [LocalizationService],
});
beforeEach(() => {
spectator = createService();
state = new SessionState(spectator.get(LocalizationService));
});
describe('#getLanguage', () => {
it('should return the current language', () => {
expect(SessionState.getLanguage(SESSION_STATE_DATA)).toEqual(SESSION_STATE_DATA.language);
});
});
describe('#getTenant', () => {
it('should return the tenant object', () => {
expect(SessionState.getTenant(SESSION_STATE_DATA)).toEqual(SESSION_STATE_DATA.tenant);
});
});
describe('#SetLanguage', () => {
it('should set the language and dispatch the GetAppConfiguration action', () => {
let patchedData;
let dispatchedData;
const patchState = jest.fn(data => (patchedData = data));
const dispatch = jest.fn(action => {
dispatchedData = action;
return of({});
});
const spy = jest.spyOn(spectator.get(LocalizationService), 'registerLocale');
state.setLanguage({ patchState, dispatch } as any, { payload: 'en' }).subscribe();
expect(patchedData).toEqual({ language: 'en' });
expect(dispatchedData instanceof GetAppConfiguration).toBeTruthy();
expect(spy).toHaveBeenCalledWith('en');
});
});
describe('#setTenantId', () => {
it('should set the tenant', () => {
let patchedData;
const patchState = jest.fn(data => (patchedData = data));
const testTenant = { id: '54ae02ba-9289-4c1b-8521-0ea437756288', name: 'Test Tenant' };
state.setTenant({ patchState } as any, { payload: testTenant });
expect(patchedData).toEqual({ tenant: testTenant });
});
});
});

@ -37,7 +37,7 @@ import fse from 'fs-extra';
});
await execa('git', ['add', '../dist/*', '../package.json'], { stdout: 'inherit' });
await execa('git', ['commit', '-m', 'Build ng packages'], { stdout: 'inherit' });
await execa('git', ['commit', '--no-verify', '-m', 'Build ng packages'], { stdout: 'inherit' });
process.exit(0);
})();

Loading…
Cancel
Save