Browse Source

Merge branch 'master' of https://github.com/abpframework/abp into dev

pull/4617/head
mehmet-erim 6 years ago
parent
commit
bc7141a819
  1. 2
      npm/ng-packs/apps/dev-app/src/app/app.module.ts
  2. 8
      npm/ng-packs/packages/core/src/lib/core.module.ts
  3. 6
      npm/ng-packs/packages/core/src/lib/services/auth.service.ts
  4. 31
      npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts
  5. 10
      npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

2
npm/ng-packs/apps/dev-app/src/app/app.module.ts

@ -15,7 +15,7 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { APP_ROUTE_PROVIDER } from './route.provider';
const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: false })];
const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: true })];
@NgModule({
imports: [

8
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -37,7 +37,7 @@ import { SessionState } from './states/session.state';
import { CORE_OPTIONS } from './tokens/options.token';
import { noop } from './utils/common-utils';
import './utils/date-extensions';
import { getInitialData, localeInitializer } from './utils/initial-utils';
import { getInitialData, localeInitializer, configureOAuth } from './utils/initial-utils';
export function storageFactory(): OAuthStorage {
return localStorage;
@ -179,6 +179,12 @@ export class CoreModule {
useClass: ApiInterceptor,
multi: true,
},
{
provide: APP_INITIALIZER,
multi: true,
deps: [Injector, NGXS_CONFIG_PLUGIN_OPTIONS],
useFactory: configureOAuth,
},
{
provide: APP_INITIALIZER,
multi: true,

6
npm/ng-packs/packages/core/src/lib/services/auth.service.ts

@ -20,11 +20,7 @@ export class AuthService {
private oAuthService: OAuthService,
private store: Store,
@Optional() @Inject('ACCOUNT_OPTIONS') private options: any,
) {
this.oAuthService.configure(
this.store.selectSnapshot(ConfigState.getOne('environment')).oAuthConfig,
);
}
) {}
login(username: string, password: string): Observable<any> {
const tenant = this.store.selectSnapshot(SessionState.getTenant);

31
npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts

@ -3,7 +3,8 @@ import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store';
import { of } from 'rxjs';
import { GetAppConfiguration } from '../actions';
import { getInitialData, localeInitializer } from '../utils';
import { getInitialData, localeInitializer, configureOAuth } from '../utils';
import { OAuthService } from 'angular-oauth2-oidc';
@Component({
selector: 'abp-dummy',
@ -15,16 +16,30 @@ describe('InitialUtils', () => {
let spectator: Spectator<DummyComponent>;
const createComponent = createComponentFactory({
component: DummyComponent,
mocks: [Store],
mocks: [Store, OAuthService],
});
beforeEach(() => (spectator = createComponent()));
describe('#configureOAuth', () => {
test('should be called the the configure method of OAuthService', async () => {
const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get');
const oAuth = spectator.inject(OAuthService);
const configureSpy = jest.spyOn(oAuth, 'configure');
injectorSpy.mockReturnValueOnce(oAuth);
await configureOAuth(injector, { environment: { oAuthConfig: { issuer: 'test' } } })();
expect(configureSpy).toHaveBeenCalledWith({ issuer: 'test' });
});
});
describe('#getInitialData', () => {
test('should dispatch GetAppConfiguration and return', async () => {
const injector = spectator.get(Injector);
const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get');
const store = spectator.get(Store);
const store = spectator.inject(Store);
const dispatchSpy = jest.spyOn(store, 'dispatch');
injectorSpy.mockReturnValueOnce(store);
@ -40,9 +55,9 @@ describe('InitialUtils', () => {
describe('#checkAccessToken', () => {
test('should call logOut fn of OAuthService when token is valid and current user not found', async () => {
const injector = spectator.get(Injector);
const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get');
const store = spectator.get(Store);
const store = spectator.inject(Store);
const dispatchSpy = jest.spyOn(store, 'dispatch');
const logOutFn = jest.fn();
@ -58,9 +73,9 @@ describe('InitialUtils', () => {
describe('#localeInitializer', () => {
test('should resolve registerLocale', async () => {
const injector = spectator.get(Injector);
const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get');
const store = spectator.get(Store);
const store = spectator.inject(Store);
store.selectSnapshot.andCallFake(selector => selector({ SessionState: { language: 'tr' } }));
injectorSpy.mockReturnValue(store);
expect(typeof localeInitializer(injector)).toBe('function');

10
npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

@ -9,6 +9,16 @@ import { ABP } from '../models/common';
import { ConfigState } from '../states/config.state';
import { CORE_OPTIONS } from '../tokens/options.token';
export function configureOAuth(injector: Injector, options: ABP.Root) {
const fn = () => {
const oAuth = injector.get(OAuthService);
oAuth.configure(options.environment.oAuthConfig);
return Promise.resolve();
};
return fn;
}
export function getInitialData(injector: Injector) {
const fn = () => {
const store: Store = injector.get(Store);

Loading…
Cancel
Save