|
|
@ -8,10 +8,9 @@ |
|
|
import { IMock, Mock } from 'typemoq'; |
|
|
import { IMock, Mock } from 'typemoq'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Observable } from 'rxjs'; |
|
|
|
|
|
|
|
|
import { SchemasService } from 'shared'; |
|
|
import { RoutingCache, SchemasService } from 'shared'; |
|
|
|
|
|
|
|
|
import { ResolvePublishedSchemaGuard } from './resolve-published-schema.guard'; |
|
|
|
|
|
import { RouterMockup } from './router-mockup'; |
|
|
import { RouterMockup } from './router-mockup'; |
|
|
|
|
|
import { ResolvePublishedSchemaGuard } from './resolve-published-schema.guard'; |
|
|
|
|
|
|
|
|
describe('ResolvePublishedSchemaGuard', () => { |
|
|
describe('ResolvePublishedSchemaGuard', () => { |
|
|
const route = { |
|
|
const route = { |
|
|
@ -26,29 +25,48 @@ describe('ResolvePublishedSchemaGuard', () => { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let schemasService: IMock<SchemasService>; |
|
|
let schemasService: IMock<SchemasService>; |
|
|
|
|
|
let routingCache: IMock<RoutingCache>; |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
schemasService = Mock.ofType(SchemasService); |
|
|
schemasService = Mock.ofType(SchemasService); |
|
|
|
|
|
|
|
|
|
|
|
routingCache = Mock.ofType(RoutingCache); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should throw if route does not contain app name', () => { |
|
|
it('should throw if route does not contain app name', () => { |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>new RouterMockup()); |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>new RouterMockup(), routingCache.object); |
|
|
|
|
|
|
|
|
expect(() => guard.resolve(<any>{ params: {} }, <any>{})).toThrow('Route must contain app name.'); |
|
|
expect(() => guard.resolve(<any>{ params: {} }, <any>{})).toThrow('Route must contain app name.'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should throw if route does not contain schema name', () => { |
|
|
it('should throw if route does not contain schema name', () => { |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>new RouterMockup()); |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>new RouterMockup(), routingCache.object); |
|
|
|
|
|
|
|
|
expect(() => guard.resolve(<any>{ params: { appName: 'my-app' } }, <any>{})).toThrow('Route must contain schema name.'); |
|
|
expect(() => guard.resolve(<any>{ params: { appName: 'my-app' } }, <any>{})).toThrow('Route must contain schema name.'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should provide schema from cache if found', (done) => { |
|
|
|
|
|
const schema = { isPublished: true }; |
|
|
|
|
|
|
|
|
|
|
|
routingCache.setup(x => x.getValue('schema.my-schema')) |
|
|
|
|
|
.returns(() => schema); |
|
|
|
|
|
|
|
|
|
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>new RouterMockup(), routingCache.object); |
|
|
|
|
|
|
|
|
|
|
|
guard.resolve(<any>route, <any>{}) |
|
|
|
|
|
.subscribe(result => { |
|
|
|
|
|
expect(result).toBe(schema); |
|
|
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
it('should navigate to 404 page if schema is not found', (done) => { |
|
|
it('should navigate to 404 page if schema is not found', (done) => { |
|
|
schemasService.setup(x => x.getSchema('my-app', 'my-schema')) |
|
|
schemasService.setup(x => x.getSchema('my-app', 'my-schema')) |
|
|
.returns(() => Observable.of(null!)); |
|
|
.returns(() => Observable.of(null!)); |
|
|
const router = new RouterMockup(); |
|
|
const router = new RouterMockup(); |
|
|
|
|
|
|
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router); |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router, routingCache.object); |
|
|
|
|
|
|
|
|
guard.resolve(<any>route, <any>{}) |
|
|
guard.resolve(<any>route, <any>{}) |
|
|
.subscribe(result => { |
|
|
.subscribe(result => { |
|
|
@ -64,7 +82,7 @@ describe('ResolvePublishedSchemaGuard', () => { |
|
|
.returns(() => Observable.throw(null)); |
|
|
.returns(() => Observable.throw(null)); |
|
|
const router = new RouterMockup(); |
|
|
const router = new RouterMockup(); |
|
|
|
|
|
|
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router); |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router, routingCache.object); |
|
|
|
|
|
|
|
|
guard.resolve(<any>route, <any>{}) |
|
|
guard.resolve(<any>route, <any>{}) |
|
|
.subscribe(result => { |
|
|
.subscribe(result => { |
|
|
@ -82,11 +100,11 @@ describe('ResolvePublishedSchemaGuard', () => { |
|
|
.returns(() => Observable.of(schema)); |
|
|
.returns(() => Observable.of(schema)); |
|
|
const router = new RouterMockup(); |
|
|
const router = new RouterMockup(); |
|
|
|
|
|
|
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router); |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router, routingCache.object); |
|
|
|
|
|
|
|
|
guard.resolve(<any>route, <any>{}) |
|
|
guard.resolve(<any>route, <any>{}) |
|
|
.subscribe(result => { |
|
|
.subscribe(result => { |
|
|
expect(result).toBeFalsy(); |
|
|
expect(result).toBe(schema); |
|
|
expect(router.lastNavigation).toEqual(['/404']); |
|
|
expect(router.lastNavigation).toEqual(['/404']); |
|
|
|
|
|
|
|
|
done(); |
|
|
done(); |
|
|
@ -100,7 +118,7 @@ describe('ResolvePublishedSchemaGuard', () => { |
|
|
.returns(() => Observable.of(schema)); |
|
|
.returns(() => Observable.of(schema)); |
|
|
const router = new RouterMockup(); |
|
|
const router = new RouterMockup(); |
|
|
|
|
|
|
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router); |
|
|
const guard = new ResolvePublishedSchemaGuard(schemasService.object, <any>router, routingCache.object); |
|
|
|
|
|
|
|
|
guard.resolve(<any>route, <any>{}) |
|
|
guard.resolve(<any>route, <any>{}) |
|
|
.subscribe(result => { |
|
|
.subscribe(result => { |
|
|
|