import { HttpRequest } from '@angular/common/http'; import { MockModule } from '@yourcause/common/testing'; import { Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { SlotRoutingInterceptor } from './slot-routing.service'; @DescribeAngularService(SlotRoutingInterceptor, { imports: [MockModule] }) export class SlotRoutingInterceptorSpec implements Spec { @TestCase('should be able to handle while on an app slot') testSharedHandleWhileOnAppSlot (service: SlotRoutingInterceptor) { sessionStorage.setItem('currentAppSlotName', 'staging'); const request = new HttpRequest('GET', 'https://google.com'); const expectedUrl = 'https://google.com?x-ms-routing-name=staging'; let handledRequest: HttpRequest; const next = { handle: (req: HttpRequest) => { handledRequest = req; } } as any; service.intercept(request, next); expect(handledRequest.url).to.equal(expectedUrl); } @TestCase('should be able to handle while on an app slot with existing params') testSharedHandleWhileOnAppSlotWithExistingParams (service: SlotRoutingInterceptor) { sessionStorage.setItem('currentAppSlotName', 'staging'); const request = new HttpRequest('GET', 'https://google.com?some-param=value'); const expectedUrl = 'https://google.com?some-param=value&x-ms-routing-name=staging'; let handledRequest: HttpRequest; const next = { handle: (req: HttpRequest) => { handledRequest = req; } } as any; service.intercept(request, next); expect(handledRequest.url).to.equal(expectedUrl); } @TestCase('should be able to handle while not on an app slot') testSharedHandleWhileNotOnAppSlot (service: SlotRoutingInterceptor) { sessionStorage.removeItem('currentAppSlotName'); const request = new HttpRequest('GET', 'https://google.com'); const expectedUrl = 'https://google.com'; let handledRequest: HttpRequest; const next = { handle: (req: HttpRequest) => { handledRequest = req; } } as any; service.intercept(request, next); expect(handledRequest.url).to.equal(expectedUrl); } }