From 6d6d190260306325ddf98e8471a673419802a09b Mon Sep 17 00:00:00 2001 From: Jocelyn Cabildo Date: Tue, 10 Sep 2024 13:47:37 -0700 Subject: [PATCH] Update ngx-webstorage in test --- .../adoptive-parents.component.spec.ts | 5 +- .../another-information.component.spec.ts | 5 +- .../child-information.component.spec.ts | 5 +- .../contact-info-options.component.spec.ts | 6 +- .../contact-info.component.spec.ts | 5 +- .../description-timeframe.component.spec.ts | 5 +- .../verify-your-identity.component.spec.ts | 5 +- web/src/app/services/data.service.spec.ts | 74 ++++++++++--------- .../app/transom-api-client.service.spec.ts | 55 +++++++------- 9 files changed, 81 insertions(+), 84 deletions(-) diff --git a/web/src/app/route-components/adoptive-parents/adoptive-parents.component.spec.ts b/web/src/app/route-components/adoptive-parents/adoptive-parents.component.spec.ts index 0d28b334..94f5f75a 100644 --- a/web/src/app/route-components/adoptive-parents/adoptive-parents.component.spec.ts +++ b/web/src/app/route-components/adoptive-parents/adoptive-parents.component.spec.ts @@ -7,7 +7,7 @@ import { DataService } from "src/app/services/data.service"; import { Router } from "@angular/router"; import { FoiValidComponent } from "src/app/utils-components/foi-valid/foi-valid.component"; import { FoiRequest } from "src/app/models/FoiRequest"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { HttpClientTestingModule } from "@angular/common/http/testing"; import { OwlNativeDateTimeModule, OwlDateTimeModule } from "@danielmoncada/angular-datetime-picker"; import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; @@ -29,12 +29,11 @@ describe("AdoptiveParentsComponent", () => { imports: [ HttpClientTestingModule, ReactiveFormsModule, - NgxWebstorageModule.forRoot(), OwlDateTimeModule, OwlNativeDateTimeModule, FontAwesomeModule, ], - providers: [DataService, { provide: Router, useClass: MockRouter }], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/route-components/another-information/another-information.component.spec.ts b/web/src/app/route-components/another-information/another-information.component.spec.ts index 3c31854c..9208de15 100644 --- a/web/src/app/route-components/another-information/another-information.component.spec.ts +++ b/web/src/app/route-components/another-information/another-information.component.spec.ts @@ -9,7 +9,7 @@ import { MockRouter } from "../../MockClasses"; import { FoiValidComponent } from "src/app/utils-components/foi-valid/foi-valid.component"; import { FoiFileinputComponent } from "src/app/utils-components/foi-fileinput/foi-fileinput.component"; import { FoiRequest } from "src/app/models/FoiRequest"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { HttpClientTestingModule } from "@angular/common/http/testing"; import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; import { OwlNativeDateTimeModule, OwlDateTimeModule } from "@danielmoncada/angular-datetime-picker"; @@ -24,12 +24,11 @@ describe("AnotherInformationComponent", () => { imports: [ HttpClientTestingModule, ReactiveFormsModule, - NgxWebstorageModule.forRoot(), OwlDateTimeModule, OwlNativeDateTimeModule, FontAwesomeModule, ], - providers: [DataService, { provide: Router, useClass: MockRouter }], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/route-components/child-information/child-information.component.spec.ts b/web/src/app/route-components/child-information/child-information.component.spec.ts index deb647fb..d4d7735c 100644 --- a/web/src/app/route-components/child-information/child-information.component.spec.ts +++ b/web/src/app/route-components/child-information/child-information.component.spec.ts @@ -9,7 +9,7 @@ import { Router } from "@angular/router"; import { FoiValidComponent } from "src/app/utils-components/foi-valid/foi-valid.component"; import { FoiFileinputComponent } from "src/app/utils-components/foi-fileinput/foi-fileinput.component"; import { FoiRequest } from "src/app/models/FoiRequest"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { HttpClientTestingModule } from "@angular/common/http/testing"; import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; import { OwlNativeDateTimeModule, OwlDateTimeModule } from "@danielmoncada/angular-datetime-picker"; @@ -24,12 +24,11 @@ describe("ChildInformationComponent", () => { imports: [ HttpClientTestingModule, ReactiveFormsModule, - NgxWebstorageModule.forRoot(), OwlDateTimeModule, OwlNativeDateTimeModule, FontAwesomeModule, ], - providers: [DataService, { provide: Router, useClass: MockRouter }], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/route-components/contact-info-options/contact-info-options.component.spec.ts b/web/src/app/route-components/contact-info-options/contact-info-options.component.spec.ts index f013fe23..c6293b8c 100644 --- a/web/src/app/route-components/contact-info-options/contact-info-options.component.spec.ts +++ b/web/src/app/route-components/contact-info-options/contact-info-options.component.spec.ts @@ -7,7 +7,7 @@ import { MockRouter } from "../../MockClasses"; import { Router } from "@angular/router"; import { FoiRequest } from "src/app/models/FoiRequest"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { UtilsComponentsModule } from "src/app/utils-components/utils-components.module"; describe("ContactInfoOptionsComponent", () => { @@ -17,8 +17,8 @@ describe("ContactInfoOptionsComponent", () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [ContactInfoOptionsComponent], - imports: [HttpClientTestingModule, ReactiveFormsModule, NgxWebstorageModule.forRoot(), UtilsComponentsModule], - providers: [DataService, { provide: Router, useClass: MockRouter }], + imports: [HttpClientTestingModule, ReactiveFormsModule, UtilsComponentsModule], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/route-components/contact-info/contact-info.component.spec.ts b/web/src/app/route-components/contact-info/contact-info.component.spec.ts index 7d04535a..079c7459 100644 --- a/web/src/app/route-components/contact-info/contact-info.component.spec.ts +++ b/web/src/app/route-components/contact-info/contact-info.component.spec.ts @@ -8,7 +8,7 @@ import { DataService } from "src/app/services/data.service"; import { MockRouter } from "../../MockClasses"; import { Router } from "@angular/router"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { FoiRequest } from "src/app/models/FoiRequest"; import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; import { OwlNativeDateTimeModule, OwlDateTimeModule } from "@danielmoncada/angular-datetime-picker"; @@ -23,12 +23,11 @@ describe("ContactInfoComponent", () => { imports: [ HttpClientTestingModule, ReactiveFormsModule, - NgxWebstorageModule.forRoot(), OwlDateTimeModule, OwlNativeDateTimeModule, FontAwesomeModule, ], - providers: [DataService, { provide: Router, useClass: MockRouter }], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/route-components/description-timeframe/description-timeframe.component.spec.ts b/web/src/app/route-components/description-timeframe/description-timeframe.component.spec.ts index 50d4b803..d329097c 100644 --- a/web/src/app/route-components/description-timeframe/description-timeframe.component.spec.ts +++ b/web/src/app/route-components/description-timeframe/description-timeframe.component.spec.ts @@ -7,7 +7,7 @@ import { MockRouter } from "../../MockClasses"; import { Router } from "@angular/router"; import { FoiRequest } from "src/app/models/FoiRequest"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { UtilsComponentsModule } from "src/app/utils-components/utils-components.module"; import { OwlNativeDateTimeModule, OwlDateTimeModule } from "@danielmoncada/angular-datetime-picker"; import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; @@ -41,13 +41,12 @@ describe("DescriptionTimeframeComponent", () => { imports: [ HttpClientTestingModule, ReactiveFormsModule, - NgxWebstorageModule.forRoot(), UtilsComponentsModule, OwlDateTimeModule, OwlNativeDateTimeModule, FontAwesomeModule, ], - providers: [DataService, { provide: Router, useClass: MockRouter }], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/route-components/verify-your-identity/verify-your-identity.component.spec.ts b/web/src/app/route-components/verify-your-identity/verify-your-identity.component.spec.ts index 44d8c778..e72fab8f 100644 --- a/web/src/app/route-components/verify-your-identity/verify-your-identity.component.spec.ts +++ b/web/src/app/route-components/verify-your-identity/verify-your-identity.component.spec.ts @@ -5,7 +5,7 @@ import { DataService } from "src/app/services/data.service"; import { Router } from "@angular/router"; import { MockRouter } from "../../MockClasses"; import { UtilsComponentsModule } from "src/app/utils-components/utils-components.module"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { HttpClientTestingModule } from "@angular/common/http/testing"; import { FoiRequest } from "src/app/models/FoiRequest"; import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; @@ -21,13 +21,12 @@ describe("VerifyYourIdentityComponent", () => { imports: [ HttpClientTestingModule, ReactiveFormsModule, - NgxWebstorageModule.forRoot(), UtilsComponentsModule, OwlDateTimeModule, OwlNativeDateTimeModule, FontAwesomeModule, ], - providers: [DataService, { provide: Router, useClass: MockRouter }], + providers: [DataService, { provide: Router, useClass: MockRouter }, provideNgxWebstorage()], }).compileComponents(); })); diff --git a/web/src/app/services/data.service.spec.ts b/web/src/app/services/data.service.spec.ts index 4284ad90..ea77bd65 100644 --- a/web/src/app/services/data.service.spec.ts +++ b/web/src/app/services/data.service.spec.ts @@ -3,15 +3,13 @@ import { TestBed } from "@angular/core/testing"; import { DataService } from "./data.service"; import { TransomApiClientService } from "../transom-api-client.service"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; import { FoiRoute } from "../models/FoiRoute"; import { FoiRequest } from "../models/FoiRequest"; -import { of, Observable } from 'rxjs'; +import { of, Observable } from "rxjs"; class MockApiClient { - setHeader(key:string, value:string){ - - } + setHeader(key: string, value: string) {} postFoiRequest(foiRequest: FoiRequest): Observable { return of(true); } @@ -22,11 +20,12 @@ describe("DataService", () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, NgxWebstorageModule.forRoot()], + imports: [HttpClientTestingModule], providers: [ - { provide: TransomApiClientService, useClass: MockApiClient } + { provide: TransomApiClientService, useClass: MockApiClient }, + provideNgxWebstorage(), //{ provide: LocalStorageService, useClass: MockLocalStorage } - ] + ], }); service = TestBed.get(DataService); sessionStorage.removeItem("foi-request"); @@ -46,8 +45,8 @@ describe("DataService", () => { it("should set and get the current request state", () => { const foi: FoiRequest = { requestData: { - personalInfo: { foo: "bar" } - } + personalInfo: { foo: "bar" }, + }, }; service.setCurrentState(foi); let returnedState = service.getCurrentState("personalInfo", "anotherInfo"); @@ -61,13 +60,13 @@ describe("DataService", () => { it("should set current state from a FormGroup", () => { const foi: FoiRequest = { requestData: { - personalInfo: { foo: "bar" } - } + personalInfo: { foo: "bar" }, + }, }; service.setCurrentState(foi); let req = service.getCurrentState(); const testForm: any = { - value: { firstName: "Paul" } + value: { firstName: "Paul" }, }; service.setCurrentState(req, "personalInfo", testForm); @@ -75,11 +74,11 @@ describe("DataService", () => { expect(storedFoiRequest).toEqual('{"requestData":{"personalInfo":{"firstName":"Paul"}}}'); }); - it("should record a child file attachment in session storage base64 encoded", done => { + it("should record a child file attachment in session storage base64 encoded", (done) => { const f = new File(["foo"], "foo.txt", { - type: "text/plain" + type: "text/plain", }); - service.setChildFileAttachment(f).subscribe(value => { + service.setChildFileAttachment(f).subscribe((value) => { if (value) { let storedData = sessionStorage.getItem(service.childFileKey); expect(storedData).toEqual("data:text/plain;base64,Zm9v"); @@ -92,11 +91,11 @@ describe("DataService", () => { }); }); - it("should record a personal file attachment in session storage base64 encoded", done => { + it("should record a personal file attachment in session storage base64 encoded", (done) => { const f = new File(["foo"], "foo.txt", { - type: "text/plain" + type: "text/plain", }); - service.setPersonFileAttachment(f).subscribe(value => { + service.setPersonFileAttachment(f).subscribe((value) => { if (value) { let storedData = sessionStorage.getItem(service.personFileKey); expect(storedData).toEqual("data:text/plain;base64,Zm9v"); @@ -109,11 +108,11 @@ describe("DataService", () => { }); }); - it("should return a file object from session storage", done => { + it("should return a file object from session storage", (done) => { const f = new File(["foo"], "foo.txt", { - type: "text/plain" + type: "text/plain", }); - service.setPersonFileAttachment(f).subscribe(value => { + service.setPersonFileAttachment(f).subscribe((value) => { if (value) { const fReturned = service.getBlobFrom(service.personFileKey); const fr: FileReader = new FileReader(); @@ -126,8 +125,8 @@ describe("DataService", () => { }); }); - it("should return ministries from data.json", done => { - service.getMinistries().subscribe(mins => { + it("should return ministries from data.json", (done) => { + service.getMinistries().subscribe((mins) => { expect(mins).toBeTruthy(); expect(mins.length).toBeGreaterThan(1); done(); @@ -135,27 +134,30 @@ describe("DataService", () => { }); it("should return topics by request subject data.json", () => { - const topics = service.getTopicsObj({child: true, yourself: true}); + const topics = service.getTopicsObj({ child: true, yourself: true }); expect(topics).toBeTruthy(); expect(topics.length).toBeGreaterThan(1); }); - it('should submit the request through the api client', (done) => { + it("should submit the request through the api client", (done) => { const apiClient: TransomApiClientService = TestBed.get(TransomApiClientService); - spyOn(apiClient, 'setHeader').and.callThrough(); - spyOn(apiClient, 'postFoiRequest').and.callThrough(); - - const obs = service.submitRequest('token1', 'nonce1', {requestData:{personalInfo:{foo:"bar"}}}); + spyOn(apiClient, "setHeader").and.callThrough(); + spyOn(apiClient, "postFoiRequest").and.callThrough(); + + const obs = service.submitRequest("token1", "nonce1", { requestData: { personalInfo: { foo: "bar" } } }); expect(obs).toBeTruthy(); expect(apiClient.setHeader).toHaveBeenCalledTimes(2); - expect(apiClient.setHeader).toHaveBeenCalledWith( 'Authorization', 'Bearer token1' ); - expect(apiClient.setHeader).toHaveBeenCalledWith( 'captcha-nonce', 'nonce1' ); + expect(apiClient.setHeader).toHaveBeenCalledWith("Authorization", "Bearer token1"); + expect(apiClient.setHeader).toHaveBeenCalledWith("captcha-nonce", "nonce1"); - expect(apiClient.postFoiRequest).toHaveBeenCalledWith({requestData:{personalInfo:{foo:"bar"}}, attachments: []}); + expect(apiClient.postFoiRequest).toHaveBeenCalledWith({ + requestData: { personalInfo: { foo: "bar" } }, + attachments: [], + }); - obs.subscribe(retval => { + obs.subscribe((retval) => { expect(retval).toBeTruthy(); done(); - }) - } ); + }); + }); }); diff --git a/web/src/app/transom-api-client.service.spec.ts b/web/src/app/transom-api-client.service.spec.ts index 3c0e66d2..a5c9b371 100644 --- a/web/src/app/transom-api-client.service.spec.ts +++ b/web/src/app/transom-api-client.service.spec.ts @@ -2,17 +2,16 @@ import { TestBed } from "@angular/core/testing"; import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; import { TransomApiClientService } from "./transom-api-client.service"; -import { NgxWebstorageModule } from "ngx-webstorage"; +import { provideNgxWebstorage } from "ngx-webstorage"; describe("TransomApiClientService", () => { let apiClient: TransomApiClientService; let httpTestingController: HttpTestingController; - beforeEach(() => { TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, NgxWebstorageModule.forRoot()], - providers: [] + imports: [HttpClientTestingModule], + providers: [provideNgxWebstorage()], }); apiClient = TestBed.get(TransomApiClientService); httpTestingController = TestBed.get(HttpTestingController); @@ -27,39 +26,41 @@ describe("TransomApiClientService", () => { expect(apiClient).toBeTruthy(); }); - it("should make foi request submissions", done => { + it("should make foi request submissions", (done) => { const obs = apiClient.postFoiRequest({ requestData: { personalInfo: { foo: "bar" } }, attachments: [] }); expect(obs).toBeTruthy(); - obs.subscribe(value => { - expect(value).toBeTruthy(); - done(); - }); + obs.subscribe((value) => { + expect(value).toBeTruthy(); + done(); + }); - const req = httpTestingController.expectOne('/api/v1/fx/submitFoiRequest'); - expect(req.request.method).toEqual('POST'); + const req = httpTestingController.expectOne("/api/v1/fx/submitFoiRequest"); + expect(req.request.method).toEqual("POST"); expect(req.request.body).toEqual(jasmine.any(FormData)); - expect(req.request.body.get('requestData')).toEqual('{"personalInfo":{"foo":"bar"}}'); - - req.flush({data:true}); + expect(req.request.body.get("requestData")).toEqual('{"personalInfo":{"foo":"bar"}}'); + + req.flush({ data: true }); }); - it("can handle an error when making an foi request", done => { + it("can handle an error when making an foi request", (done) => { const obs = apiClient.postFoiRequest({ requestData: { personalInfo: { foo: "bar" } }, attachments: [] }); expect(obs).toBeTruthy(); - obs.subscribe(value => { - expect('not').toEqual('be here'); + obs.subscribe( + (value) => { + expect("not").toEqual("be here"); }, - error => { - expect(error).toBeTruthy(); - expect(error.statusText).toEqual('Not Found') - done(); - }); + (error) => { + expect(error).toBeTruthy(); + expect(error.statusText).toEqual("Not Found"); + done(); + } + ); - const req = httpTestingController.expectOne('/api/v1/fx/submitFoiRequest'); - expect(req.request.method).toEqual('POST'); + const req = httpTestingController.expectOne("/api/v1/fx/submitFoiRequest"); + expect(req.request.method).toEqual("POST"); expect(req.request.body).toEqual(jasmine.any(FormData)); - expect(req.request.body.get('requestData')).toEqual('{"personalInfo":{"foo":"bar"}}'); - - req.flush("Not Found on this api", { status: 403, statusText: 'Not Found' }); + expect(req.request.body.get("requestData")).toEqual('{"personalInfo":{"foo":"bar"}}'); + + req.flush("Not Found on this api", { status: 403, statusText: "Not Found" }); }); });