diff --git a/npm/ng-packs/package.json b/npm/ng-packs/package.json index 42e9c733f2..3774a5705d 100644 --- a/npm/ng-packs/package.json +++ b/npm/ng-packs/package.json @@ -92,6 +92,7 @@ "prettier --write", "tslint --fix", "git add" - ] + ], + "dist/*": [] } } diff --git a/npm/ng-packs/packages/core/src/lib/states/session.state.ts b/npm/ng-packs/packages/core/src/lib/states/session.state.ts index 544bd42b2b..9f90e0ded9 100644 --- a/npm/ng-packs/packages/core/src/lib/states/session.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/session.state.ts @@ -35,7 +35,7 @@ export class SessionState { } @Action(SetTenant) - setTenantId({ patchState }: StateContext, { payload }: SetTenant) { + setTenant({ patchState }: StateContext, { payload }: SetTenant) { patchState({ tenant: payload, }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index 2d4bd69c49..c01064152e 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -109,7 +109,7 @@ export const CONFIG_STATE_DATA = { }, } as Config.State; -describe('ConfigService', () => { +describe('ConfigState', () => { let spectator: SpectatorService; let store: SpyObject; let service: ConfigService; diff --git a/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts new file mode 100644 index 0000000000..412ed8d9ab --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts @@ -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; + 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 }); + }); + }); +}); diff --git a/npm/ng-packs/scripts/build.js b/npm/ng-packs/scripts/build.js index 92e145077e..a74863a2a0 100644 --- a/npm/ng-packs/scripts/build.js +++ b/npm/ng-packs/scripts/build.js @@ -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); })();