mengw15 commented on code in PR #6467: URL: https://github.com/apache/texera/pull/6467#discussion_r3598699393
########## frontend/src/app/dashboard/service/admin/user/admin-user.service.spec.ts: ########## @@ -0,0 +1,150 @@ +/** + * 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 { TestBed } from "@angular/core/testing"; +import { + AdminUserService, + USER_LIST_URL, + USER_UPDATE_URL, + USER_ADD_URL, + USER_CREATED_FILES, + USER_CREATED_DATASETS, + USER_CREATED_WORKFLOWS, + USER_ACCESS_FILES, + USER_ACCESS_WORKFLOWS, + USER_QUOTA_SIZE, + USER_DELETE_EXECUTION_COLLECTION, +} from "./admin-user.service"; +import { Role } from "../../../../common/type/user"; + +describe("AdminUserService", () => { + let service: AdminUserService; + let httpMock: HttpTestingController; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [AdminUserService], + }); + service = TestBed.inject(AdminUserService); + httpMock = TestBed.inject(HttpTestingController); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it("should be created", () => { + expect(service).toBeTruthy(); + }); + + it("getUserList() GETs the list endpoint", () => { + const users = [{ uid: 1 } as any]; + let result: readonly any[] | undefined; + service.getUserList().subscribe(r => (result = r)); + + const req = httpMock.expectOne(USER_LIST_URL); + expect(req.request.method).toEqual("GET"); + req.flush(users); + + expect(result).toEqual(users); + }); + + it("updateUser() PUTs the full user record", () => { + service.updateUser(1, "Alice", "[email protected]", Role.ADMIN, "vip").subscribe(); + + const req = httpMock.expectOne(USER_UPDATE_URL); + expect(req.request.method).toEqual("PUT"); + expect(req.request.body).toEqual({ + uid: 1, + name: "Alice", + email: "[email protected]", + role: Role.ADMIN, + comment: "vip", + }); + req.flush(null); + }); + + it("addUser() POSTs an empty body to the trailing-slash add endpoint", () => { + service.addUser().subscribe(); + + const req = httpMock.expectOne(`${USER_ADD_URL}/`); + expect(req.request.method).toEqual("POST"); + expect(req.request.body).toEqual({}); + req.flush({}); + }); + + it("getUploadedFiles() sends the uid as a user_id query param", () => { Review Comment: Not blocking — a note on the three methods this and the two tests below pin: `getUploadedFiles`, `getCreatedDatasets`, and `getAccessFiles` are orphaned dead code calling endpoints that no longer exist. `AdminUserResource` (`/admin/user`) only defines `list / update / add / created_workflows / access_workflows / user_quota_size / deleteCollection`; a repo-wide search finds no `uploaded_files` or `access_files` route anywhere (`created_datasets` exists only under the session-scoped `/quota` resource); and no frontend component calls any of the three — calling them would 404. They were live once, but #2781 (Remove File-Related Components) deleted their callers and backend routes and left the service methods behind. Since `HttpTestingController` intercepts everything, these tests stay green while the methods themselves are unusable. Same situation as #6289/#6305: consider dropping these three tests and deleting the three methods (+ URL constants) in a follow-up instead of cementing them. The other eight tests all target real routes and look good. -- 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]
