From 44dbe1d955db6b4f7d29a505f12043a8b0920525 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sat, 10 Jun 2017 17:45:13 +0200 Subject: [PATCH] Service for Plans Service. --- .../app/shared/services/plans.service.spec.ts | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/Squidex/app/shared/services/plans.service.spec.ts diff --git a/src/Squidex/app/shared/services/plans.service.spec.ts b/src/Squidex/app/shared/services/plans.service.spec.ts new file mode 100644 index 000000000..388b0b508 --- /dev/null +++ b/src/Squidex/app/shared/services/plans.service.spec.ts @@ -0,0 +1,99 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved + */ + +import { Response, ResponseOptions } from '@angular/http'; +import { Observable } from 'rxjs'; +import { IMock, Mock, Times } from 'typemoq'; + +import { + AppPlansDto, + ApiUrlConfig, + AuthService, + ChangePlanDto, + PlanDto, + PlansService, + Version +} from './../'; + +describe('PlansService', () => { + let authService: IMock; + let plansService: PlansService; + let version = new Version('1'); + + beforeEach(() => { + authService = Mock.ofType(AuthService); + plansService = new PlansService(authService.object, new ApiUrlConfig('http://service/p/')); + }); + + it('should make get request to get app plans', () => { + authService.setup(x => x.authGet('http://service/p/api/apps/my-app/plans', version)) + .returns(() => Observable.of( + new Response( + new ResponseOptions({ + body: { + currentPlanId: '123', + hasConfigured: true, + hasPortal: true, + planOwner: '456', + plans: [{ + id: 'free', + name: 'Free', + costs: '14 €', + maxApiCalls: 1000, + maxAssetSize: 1500, + maxContributors: 2500 + }, { + id: 'prof', + name: 'Prof', + costs: '18 €', + maxApiCalls: 4000, + maxAssetSize: 5500, + maxContributors: 6500 + }] + } + }) + ) + )) + .verifiable(Times.once()); + + let plans: AppPlansDto | null = null; + + plansService.getPlans('my-app', version).subscribe(result => { + plans = result; + }).unsubscribe(); + + expect(plans).toEqual( + new AppPlansDto( + '123', + '456', + true, + true, + [ + new PlanDto('free', 'Free', '14 €', 1000, 1500, 2500), + new PlanDto('prof', 'Prof', '18 €', 4000, 5500, 6500) + ] + )); + + authService.verifyAll(); + }); + + it('should make put request to change plan', () => { + const dto = new ChangePlanDto('enterprise'); + + authService.setup(x => x.authPut('http://service/p/api/apps/my-app/plan', dto, version)) + .returns(() => Observable.of( + new Response( + new ResponseOptions() + ) + )) + .verifiable(Times.once()); + + plansService.putPlan('my-app', dto, version); + + authService.verifyAll(); + }); +}); \ No newline at end of file