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/17 05:22:15 UTC
(texera) branch gh-readonly-queue/main/pr-6462-16b917c4538c7772c223d26047a1e0233648f419 created (now fb28f08968)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-6462-16b917c4538c7772c223d26047a1e0233648f419
in repository https://gitbox.apache.org/repos/asf/texera.git
at fb28f08968 test(frontend): add unit tests for FlarumService (#6462)
This branch includes the following new commits:
new fb28f08968 test(frontend): add unit tests for FlarumService (#6462)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(texera) 01/01: test(frontend): add unit tests for FlarumService (#6462)
Posted by gi...@apache.org.
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-6462-16b917c4538c7772c223d26047a1e0233648f419
in repository https://gitbox.apache.org/repos/asf/texera.git
commit fb28f08968b56afda722b9d4f0b2df1e3f087aa9
Author: Matthew B. <mg...@uci.edu>
AuthorDate: Thu Jul 16 22:22:03 2026 -0700
test(frontend): add unit tests for FlarumService (#6462)
### What changes were proposed in this PR?
- Adds flarum.service.spec.ts covering FlarumService; no production code
changed.
- Verifies the register and auth POST payloads and headers derived from
the current user, including username derivation.
- Covers the negative case where no user is logged in.
### Any related issues, documentation, discussions?
Closes: #6450
### How was this PR tested?
- Run `cd frontend && npx nx test gui
--include="**/flarum.service.spec.ts"`, expect 5 passed.
- Full frontend suite runs in CI via `yarn test:ci`, selected by the
auto-applied `frontend` label.
### Was this PR authored or co-authored using generative AI tooling?
Co-authored with Claude Opus 4.8 in compliance with ASF
---
.../service/user/flarum/flarum.service.spec.ts | 118 +++++++++++++++++++++
1 file changed, 118 insertions(+)
diff --git a/frontend/src/app/dashboard/service/user/flarum/flarum.service.spec.ts b/frontend/src/app/dashboard/service/user/flarum/flarum.service.spec.ts
new file mode 100644
index 0000000000..76ac6a0f0e
--- /dev/null
+++ b/frontend/src/app/dashboard/service/user/flarum/flarum.service.spec.ts
@@ -0,0 +1,118 @@
+/**
+ * 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 { FlarumService } from "./flarum.service";
+import { UserService } from "../../../../common/service/user/user.service";
+
+describe("FlarumService", () => {
+ let service: FlarumService;
+ let httpMock: HttpTestingController;
+
+ const mockUser = { uid: 42, email: "alice@example.com", googleId: "secret-token" };
+ const getCurrentUser = vi.fn();
+
+ beforeEach(() => {
+ getCurrentUser.mockReturnValue(mockUser);
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [FlarumService, { provide: UserService, useValue: { getCurrentUser } }],
+ });
+ service = TestBed.inject(FlarumService);
+ httpMock = TestBed.inject(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpMock.verify();
+ });
+
+ it("should be created", () => {
+ expect(service).toBeTruthy();
+ });
+
+ describe("register", () => {
+ it("POSTs a user with a username derived from email local-part + uid", () => {
+ service.register().subscribe();
+
+ const req = httpMock.expectOne("forum/api/users");
+ expect(req.request.method).toEqual("POST");
+ expect(req.request.body.data.attributes).toEqual({
+ username: "alice42",
+ email: "alice@example.com",
+ password: "secret-token",
+ });
+ expect(req.request.headers.get("Authorization")).toContain("Token ");
+ req.flush({});
+ });
+
+ it("handles an email that contains multiple '@' by using only the first local-part segment", () => {
+ getCurrentUser.mockReturnValue({ uid: 7, email: "weird@name@example.com", googleId: "g" });
+
+ service.register().subscribe();
+
+ const req = httpMock.expectOne("forum/api/users");
+ expect(req.request.body.data.attributes.username).toEqual("weird7");
+ req.flush({});
+ });
+
+ it("propagates HTTP errors to the subscriber", () => {
+ const onError = vi.fn();
+ service.register().subscribe({ error: onError });
+
+ const req = httpMock.expectOne("forum/api/users");
+ req.flush("boom", { status: 500, statusText: "Server Error" });
+
+ expect(onError).toHaveBeenCalledTimes(1);
+ expect(onError.mock.calls[0][0].status).toEqual(500);
+ });
+ });
+
+ describe("auth", () => {
+ it("POSTs credentials to the token endpoint", () => {
+ service.auth().subscribe();
+
+ const req = httpMock.expectOne("forum/api/token");
+ expect(req.request.method).toEqual("POST");
+ expect(req.request.body).toEqual({
+ identification: "alice@example.com",
+ password: "secret-token",
+ remember: "1",
+ });
+ req.flush({});
+ });
+
+ it("propagates HTTP errors to the subscriber", () => {
+ const onError = vi.fn();
+ service.auth().subscribe({ error: onError });
+
+ const req = httpMock.expectOne("forum/api/token");
+ req.flush("boom", { status: 500, statusText: "Server Error" });
+
+ expect(onError).toHaveBeenCalledTimes(1);
+ expect(onError.mock.calls[0][0].status).toEqual(500);
+ });
+ });
+
+ it("throws when no user is logged in", () => {
+ getCurrentUser.mockReturnValue(undefined);
+ expect(() => service.register()).toThrow();
+ expect(() => service.auth()).toThrow();
+ });
+});