You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@texera.apache.org by gi...@apache.org on 2026/07/09 21:56:42 UTC
(texera) 01/01: test(frontend): cover ShareAccessService (#6296)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-6296-29233cc86ed8687f5eafd6b5b7dd4e51b7000c84
in repository https://gitbox.apache.org/repos/asf/texera.git
commit 12f9f1a45240d5316703c2385f3bbe0159997b25
Author: Neil Ketteringham <53...@users.noreply.github.com>
AuthorDate: Thu Jul 9 14:56:17 2026 -0700
test(frontend): cover ShareAccessService (#6296)
### What changes were proposed in this PR?
Adds a unit test spec for ShareAccessService, the REST client for
grant/revoke/owner/list of resource share-access endpoints (no
production code changes). Covers grantAccess, revokeAccess, getOwner,
and getAccessList, using Angular's HttpTestingController to pin exact
URL composition and HTTP method per endpoint.
### Any related issues, documentation, discussions?
Closes #6261.
### How was this PR tested?
`share-access.service.spec.ts` passes locally via ng test (Vitest
runner, happy-dom, TestBed + HttpTestingController — no real network
calls), along with `yarn format:fix` and `yarn lint`.
### Was this PR authored or co-authored using generative AI tooling?
No.
---
.../user/share-access/share-access.service.spec.ts | 97 ++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/frontend/src/app/dashboard/service/user/share-access/share-access.service.spec.ts b/frontend/src/app/dashboard/service/user/share-access/share-access.service.spec.ts
new file mode 100644
index 0000000000..f97b3f3964
--- /dev/null
+++ b/frontend/src/app/dashboard/service/user/share-access/share-access.service.spec.ts
@@ -0,0 +1,97 @@
+/**
+ * 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 { Privilege, 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 = "johnDoe@gmail.com";
+ 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", () => {
+ let owner: string | undefined;
+ service.getOwner(type, id).subscribe(res => {
+ owner = res;
+ });
+ const req = httpMock.expectOne(`${BASE}/${type}/owner/${id}`);
+
+ expect(req.request.method).toBe("GET");
+ expect(req.request.responseType).toBe("text");
+ req.flush("owner@example.com");
+ expect(owner).toBe("owner@example.com");
+ });
+
+ it("getAccessList should resolve to an array", () => {
+ const mockList: ReadonlyArray<ShareAccess> = [
+ { email: "JohnDaBeast1999@example.com", name: "John", privilege: Privilege.READ },
+ { email: "alice@example.com", name: "Alice", privilege: Privilege.WRITE },
+ ];
+
+ 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).toEqual(mockList);
+ });
+});