|
|
|
@ -20,10 +20,10 @@ describe('AppsStoreService', () => { |
|
|
|
const now = DateTime.now(); |
|
|
|
|
|
|
|
const oldApps = [ |
|
|
|
new AppDto('id', 'old-name', 'Owner', now, now, 'Free', 'Plan'), |
|
|
|
new AppDto('id', 'old-name', 'Owner', now, now, 'Free', 'Plan') |
|
|
|
new AppDto('id1', 'old-name1', 'Owner', now, now, 'Free', 'Plan'), |
|
|
|
new AppDto('id2', 'old-name2', 'Owner', now, now, 'Free', 'Plan') |
|
|
|
]; |
|
|
|
const newApp = new AppDto('id', 'new-name', 'Owner', now, now, 'Free', 'Plan'); |
|
|
|
const newApp = new AppDto('id3', 'new-name', 'Owner', now, now, 'Free', 'Plan'); |
|
|
|
|
|
|
|
let appsService: IMock<AppsService>; |
|
|
|
|
|
|
|
@ -56,27 +56,69 @@ describe('AppsStoreService', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should add app to cache when created', () => { |
|
|
|
appsService.setup(x => x.postApp(It.isAny())) |
|
|
|
const request = new CreateAppDto(newApp.name); |
|
|
|
|
|
|
|
appsService.setup(x => x.postApp(request)) |
|
|
|
.returns(() => Observable.of(newApp)) |
|
|
|
.verifiable(Times.once()); |
|
|
|
|
|
|
|
const store = new AppsStoreService(appsService.object); |
|
|
|
|
|
|
|
let result1: AppDto[] | null = null; |
|
|
|
let result2: AppDto[] | null = null; |
|
|
|
|
|
|
|
store.apps.subscribe(x => { |
|
|
|
result1 = x; |
|
|
|
}).unsubscribe(); |
|
|
|
|
|
|
|
store.createApp(request, now).subscribe(); |
|
|
|
|
|
|
|
store.apps.subscribe(x => { |
|
|
|
result2 = x; |
|
|
|
}).unsubscribe(); |
|
|
|
|
|
|
|
expect(result1).toEqual(oldApps); |
|
|
|
expect(result2).toEqual(oldApps.concat([newApp])); |
|
|
|
|
|
|
|
appsService.verifyAll(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should remove app from cache when archived', () => { |
|
|
|
const request = new CreateAppDto(newApp.name); |
|
|
|
|
|
|
|
appsService.setup(x => x.postApp(request)) |
|
|
|
.returns(() => Observable.of(newApp)) |
|
|
|
.verifiable(Times.once()); |
|
|
|
|
|
|
|
appsService.setup(x => x.deleteApp(newApp.name)) |
|
|
|
.returns(() => Observable.of({})) |
|
|
|
.verifiable(Times.once()); |
|
|
|
|
|
|
|
const store = new AppsStoreService(appsService.object); |
|
|
|
|
|
|
|
let result1: AppDto[] | null = null; |
|
|
|
let result2: AppDto[] | null = null; |
|
|
|
let result3: AppDto[] | null = null; |
|
|
|
|
|
|
|
store.apps.subscribe(x => { |
|
|
|
result1 = x; |
|
|
|
}).unsubscribe(); |
|
|
|
|
|
|
|
store.createApp(new CreateAppDto('new-name'), now).subscribe(); |
|
|
|
store.createApp(request, now).subscribe(); |
|
|
|
|
|
|
|
store.apps.subscribe(x => { |
|
|
|
result2 = x; |
|
|
|
}).unsubscribe(); |
|
|
|
|
|
|
|
store.deleteApp(newApp.name).subscribe(); |
|
|
|
|
|
|
|
store.apps.subscribe(x => { |
|
|
|
result3 = x; |
|
|
|
}).unsubscribe(); |
|
|
|
|
|
|
|
expect(result1).toEqual(oldApps); |
|
|
|
expect(JSON.stringify(result2)).toEqual(JSON.stringify(oldApps.concat([newApp]))); |
|
|
|
expect(result2).toEqual(oldApps.concat([newApp])); |
|
|
|
expect(result3).toEqual(oldApps); |
|
|
|
|
|
|
|
appsService.verifyAll(); |
|
|
|
}); |
|
|
|
@ -84,7 +126,7 @@ describe('AppsStoreService', () => { |
|
|
|
it('should select app', (done) => { |
|
|
|
const store = new AppsStoreService(appsService.object); |
|
|
|
|
|
|
|
store.selectApp('old-name').subscribe(isSelected => { |
|
|
|
store.selectApp(oldApps[0].name).subscribe(isSelected => { |
|
|
|
expect(isSelected).toBeTruthy(); |
|
|
|
|
|
|
|
appsService.verifyAll(); |
|
|
|
|