Copilot commented on code in PR #6297: URL: https://github.com/apache/texera/pull/6297#discussion_r3555553340
########## frontend/src/app/dashboard/service/admin/settings/admin-settings.service.spec.ts: ########## @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { AdminSettingsService } from "./admin-settings.service"; +import { TestBed } from "@angular/core/testing"; + +describe("AdminSettingsService", () => { + let httpMock: HttpTestingController; + let service: AdminSettingsService; + + const BASE_URL = "/api/admin/settings"; + const EXAMPLE_SETTING = "multipart_upload_chunk_size_mib"; + const EXAMPLE_SETTING_VALUE = "4"; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [AdminSettingsService], + }); + httpMock = TestBed.inject(HttpTestingController); + service = TestBed.inject(AdminSettingsService); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it("an empty getSetting body should map to null", () => { + let result: string | null | undefined; + service.getSetting(EXAMPLE_SETTING).subscribe(res => { + result = res; + }); + + const req = httpMock.expectOne(`${BASE_URL}/${EXAMPLE_SETTING}`); + + req.flush(""); + + expect(req.request.method).toBe("GET"); + expect(result).toBeNull(); + }); + + it("a getSetting body should map to its value", () => { + let result: string | undefined; + service.getSetting(EXAMPLE_SETTING).subscribe(res => { + result = res; + }); + + const req = httpMock.expectOne(`${BASE_URL}/${EXAMPLE_SETTING}`); + + req.flush({ key: EXAMPLE_SETTING, value: EXAMPLE_SETTING_VALUE }); + expect(req.request.method).toBe("GET"); + expect(result).toBe(EXAMPLE_SETTING_VALUE); + }); + + it("updateSetting issues a PUT request with value and credentials", () => { + service.updateSetting(EXAMPLE_SETTING, EXAMPLE_SETTING_VALUE).subscribe(); + + const req = httpMock.expectOne(`${BASE_URL}/${EXAMPLE_SETTING}`); + + req.flush(null); + expect(req.request.method).toBe("PUT"); + expect(req.request.body).toEqual({ value: EXAMPLE_SETTING_VALUE }); + expect(req.request.withCredentials).toBe(true); + }); + + it("resetSetting issues an PUT request with an empty body", () => { Review Comment: The test name says "PUT" but `resetSetting` is expected to issue a `POST` (and the assertion below checks for `POST`). Update the description to avoid misleading failures when scanning test output. ########## frontend/src/app/dashboard/service/admin/settings/admin-settings.service.spec.ts: ########## @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { AdminSettingsService } from "./admin-settings.service"; +import { TestBed } from "@angular/core/testing"; + +describe("AdminSettingsService", () => { + let httpMock: HttpTestingController; + let service: AdminSettingsService; + + const BASE_URL = "/api/admin/settings"; + const EXAMPLE_SETTING = "multipart_upload_chunk_size_mib"; + const EXAMPLE_SETTING_VALUE = "4"; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [AdminSettingsService], + }); + httpMock = TestBed.inject(HttpTestingController); + service = TestBed.inject(AdminSettingsService); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it("an empty getSetting body should map to null", () => { + let result: string | null | undefined; + service.getSetting(EXAMPLE_SETTING).subscribe(res => { + result = res; + }); + + const req = httpMock.expectOne(`${BASE_URL}/${EXAMPLE_SETTING}`); + + req.flush(""); Review Comment: `req.flush("")` doesn't accurately represent an "empty/absent" JSON response for `HttpClient` (responseType `json`), and it can mask parsing/shape issues. Flush `null` (or `{}`) so this test matches how Angular delivers an empty body (as `null`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
