Copilot commented on code in PR #6296: URL: https://github.com/apache/texera/pull/6296#discussion_r3554814127
########## frontend/src/app/dashboard/service/user/share-access/share-access.service.spec.ts: ########## @@ -0,0 +1,94 @@ +/** + * 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 { BASE, ShareAccessService } from "./share-access.service"; +import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { TestBed } from "@angular/core/testing"; +import { ShareAccess } from "../../../type/share-access.interface"; + +describe("ShareAccessService", () => { + let service: ShareAccessService; + let httpMock: HttpTestingController; + + const type: string = "resource"; + const id: number = 42; + const email: string = "[email protected]"; + const privilege: string = "write"; + const username: string = "johnDaBeast1999"; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ShareAccessService], + }); + service = TestBed.inject(ShareAccessService); + httpMock = TestBed.inject(HttpTestingController); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it("grantAccess composes the correct PUT url", () => { + service.grantAccess(type, id, email, privilege).subscribe(); + + const req = httpMock.expectOne(`${BASE}/${type}/grant/${id}/${email}/${privilege}`); + + expect(req.request.method).toBe("PUT"); + req.flush(null); + }); + + it("revokeAccess composes the correct DELETE url", () => { + service.revokeAccess(type, id, username).subscribe(); + + const req = httpMock.expectOne(`${BASE}/${type}/revoke/${id}/${username}`); + + expect(req.request.method).toBe("DELETE"); + req.flush(null); + }); + + it("getOwner should respond with type text", () => { + service.getOwner(type, id).subscribe(); + + const req = httpMock.expectOne(`${BASE}/${type}/owner/${id}`); + + expect(req.request.method).toBe("GET"); + expect(req.request.responseType).toBe("text"); + req.flush(null); + }); Review Comment: `getOwner` returns `Observable<string>` with `responseType: "text"`, but the test flushes `null` and doesn't assert the emitted owner value. This can mask regressions and may fail if the testing backend enforces a text body. ########## frontend/src/app/dashboard/service/user/share-access/share-access.service.spec.ts: ########## @@ -0,0 +1,94 @@ +/** + * 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 { BASE, ShareAccessService } from "./share-access.service"; +import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { TestBed } from "@angular/core/testing"; +import { ShareAccess } from "../../../type/share-access.interface"; Review Comment: The spec imports `ShareAccess` but the `getAccessList` mock data uses `username` and lowercase privilege strings, which doesn't match the `ShareAccess` interface (`email`, `name`, `Privilege` enum). Using correctly-shaped mock responses makes the test validate the real contract. ########## frontend/src/app/dashboard/service/user/share-access/share-access.service.spec.ts: ########## @@ -0,0 +1,94 @@ +/** + * 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 { BASE, ShareAccessService } from "./share-access.service"; +import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { TestBed } from "@angular/core/testing"; +import { ShareAccess } from "../../../type/share-access.interface"; + +describe("ShareAccessService", () => { + let service: ShareAccessService; + let httpMock: HttpTestingController; + + const type: string = "resource"; + const id: number = 42; + const email: string = "[email protected]"; + const privilege: string = "write"; + const username: string = "johnDaBeast1999"; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ShareAccessService], + }); + service = TestBed.inject(ShareAccessService); + httpMock = TestBed.inject(HttpTestingController); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it("grantAccess composes the correct PUT url", () => { + service.grantAccess(type, id, email, privilege).subscribe(); + + const req = httpMock.expectOne(`${BASE}/${type}/grant/${id}/${email}/${privilege}`); + + expect(req.request.method).toBe("PUT"); + req.flush(null); + }); + + it("revokeAccess composes the correct DELETE url", () => { + service.revokeAccess(type, id, username).subscribe(); + + const req = httpMock.expectOne(`${BASE}/${type}/revoke/${id}/${username}`); + + expect(req.request.method).toBe("DELETE"); + req.flush(null); + }); + + it("getOwner should respond with type text", () => { + service.getOwner(type, id).subscribe(); + + const req = httpMock.expectOne(`${BASE}/${type}/owner/${id}`); + + expect(req.request.method).toBe("GET"); + expect(req.request.responseType).toBe("text"); + req.flush(null); + }); + + it("getAccessList should resolve to an array", () => { + const mockList = [ + { username: "JohnDaBeast1999", privilege: "write" }, + { username: "alice", privilege: "read" }, + ]; + + let result: ReadonlyArray<ShareAccess> | undefined; + service.getAccessList(type, id).subscribe(res => { + result = res; + }); + + const req = httpMock.expectOne(`${BASE}/${type}/list/${id}`); + + expect(req.request.method).toBe("GET"); + req.flush(mockList); + + expect(result).toBe(mockList); + }); Review Comment: `getAccessList` currently asserts referential equality (`toBe`) and flushes mock objects that don't match `ShareAccess`. This makes the test brittle and less representative of real API responses. Prefer a correctly typed mock payload and a deep equality assertion. -- 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]
