You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "Ma77Ball (via GitHub)" <gi...@apache.org> on 2026/07/16 10:36:46 UTC
[PR] test(frontend): add unit tests for AuthService [texera]
Ma77Ball opened a new pull request, #6470:
URL: https://github.com/apache/texera/pull/6470
### What changes were proposed in this PR?
- Adds auth.service.spec.ts covering AuthService; no production code changed.
- Verifies the static access-token helpers and the login, register and Google HTTP endpoints.
- Covers logout and the loginWithExistingToken branches (no token, expired, valid, invite-only inactive).
### Any related issues, documentation, discussions?
Closes: #6458
### How was this PR tested?
- Run `cd frontend && npx nx test gui --include="**/auth.service.spec.ts"`, expect 10 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
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(frontend): add unit tests for AuthService [texera]
Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan merged PR #6470:
URL: https://github.com/apache/texera/pull/6470
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(frontend): add unit tests for AuthService [texera]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6470:
URL: https://github.com/apache/texera/pull/6470#issuecomment-4990875497
<!-- texera-reviewer-suggestion -->
### Automated Reviewer Suggestions
Based on the `git blame` history of the changed files, we recommend the following reviewers:
- No candidates found from `git blame` history.
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(frontend): add unit tests for AuthService [texera]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6470:
URL: https://github.com/apache/texera/pull/6470#discussion_r3598621129
##########
frontend/src/app/common/service/user/auth.service.spec.ts:
##########
@@ -0,0 +1,187 @@
+/**
+ * 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 { JwtHelperService } from "@auth0/angular-jwt";
+import { NzModalService } from "ng-zorro-antd/modal";
+import { AppSettings } from "../../app-setting";
+import { Role } from "../../type/user";
+import { AuthService, TOKEN_KEY } from "./auth.service";
+import { NotificationService } from "../notification/notification.service";
+import { GmailService } from "../gmail/gmail.service";
+import { GuiConfigService } from "../gui-config.service";
+
+describe("AuthService", () => {
+ let service: AuthService;
+ let httpMock: HttpTestingController;
+ let jwt: {
+ isTokenExpired: ReturnType<typeof vi.fn>;
+ decodeToken: ReturnType<typeof vi.fn>;
+ getTokenExpirationDate: ReturnType<typeof vi.fn>;
+ };
+ let notification: { error: ReturnType<typeof vi.fn> };
+ let config: { env: { inviteOnly: boolean } };
+ let modal: { info: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn> };
+
+ const api = AppSettings.getApiEndpoint();
+ const claims = {
+ role: Role.REGULAR,
+ userId: 5,
+ email: "u@x.com",
+ sub: "Ursula",
+ googleId: "g",
+ googleAvatar: "a",
+ comment: "c",
+ joiningReason: "r",
+ };
+
+ beforeEach(() => {
+ localStorage.clear();
+ jwt = {
+ isTokenExpired: vi.fn().mockReturnValue(false),
+ decodeToken: vi.fn().mockReturnValue(claims),
+ getTokenExpirationDate: vi.fn().mockReturnValue(new Date(Date.now() + 60_000)),
+ };
+ notification = { error: vi.fn() };
+ config = { env: { inviteOnly: false } };
+ modal = { info: vi.fn(), create: vi.fn() };
+
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [
+ AuthService,
+ { provide: JwtHelperService, useValue: jwt },
+ { provide: NotificationService, useValue: notification },
+ { provide: GmailService, useValue: {} },
+ { provide: GuiConfigService, useValue: config },
+ { provide: NzModalService, useValue: modal },
+ ],
+ });
+ service = TestBed.inject(AuthService);
+ httpMock = TestBed.inject(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpMock.verify();
+ localStorage.clear();
+ });
Review Comment:
`loginWithExistingToken()` schedules an RxJS `timer(...)` via `registerAutoLogout()` for the valid-token path. In this spec, the valid-token test sets `getTokenExpirationDate()` to ~60s in the future, but the suite never calls `logout()` / unsubscribes afterward, leaving a real pending timer handle that can keep Vitest alive or introduce late side effects in later tests. Clean up the subscription in `afterEach` (or use fake timers and reset to real timers).
##########
frontend/src/app/common/service/user/auth.service.spec.ts:
##########
@@ -0,0 +1,187 @@
+/**
+ * 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 { JwtHelperService } from "@auth0/angular-jwt";
+import { NzModalService } from "ng-zorro-antd/modal";
+import { AppSettings } from "../../app-setting";
+import { Role } from "../../type/user";
+import { AuthService, TOKEN_KEY } from "./auth.service";
+import { NotificationService } from "../notification/notification.service";
+import { GmailService } from "../gmail/gmail.service";
+import { GuiConfigService } from "../gui-config.service";
+
+describe("AuthService", () => {
+ let service: AuthService;
+ let httpMock: HttpTestingController;
+ let jwt: {
+ isTokenExpired: ReturnType<typeof vi.fn>;
+ decodeToken: ReturnType<typeof vi.fn>;
+ getTokenExpirationDate: ReturnType<typeof vi.fn>;
+ };
+ let notification: { error: ReturnType<typeof vi.fn> };
+ let config: { env: { inviteOnly: boolean } };
+ let modal: { info: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn> };
+
+ const api = AppSettings.getApiEndpoint();
+ const claims = {
+ role: Role.REGULAR,
+ userId: 5,
+ email: "u@x.com",
+ sub: "Ursula",
+ googleId: "g",
+ googleAvatar: "a",
+ comment: "c",
+ joiningReason: "r",
+ };
+
+ beforeEach(() => {
+ localStorage.clear();
+ jwt = {
+ isTokenExpired: vi.fn().mockReturnValue(false),
+ decodeToken: vi.fn().mockReturnValue(claims),
+ getTokenExpirationDate: vi.fn().mockReturnValue(new Date(Date.now() + 60_000)),
+ };
+ notification = { error: vi.fn() };
+ config = { env: { inviteOnly: false } };
+ modal = { info: vi.fn(), create: vi.fn() };
+
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [
+ AuthService,
+ { provide: JwtHelperService, useValue: jwt },
+ { provide: NotificationService, useValue: notification },
+ { provide: GmailService, useValue: {} },
+ { provide: GuiConfigService, useValue: config },
+ { provide: NzModalService, useValue: modal },
+ ],
+ });
+ service = TestBed.inject(AuthService);
+ httpMock = TestBed.inject(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpMock.verify();
+ localStorage.clear();
+ });
+
+ it("should be created", () => {
+ expect(service).toBeTruthy();
+ });
+
+ describe("static access-token helpers", () => {
+ it("set/get/remove roundtrip through localStorage", () => {
+ expect(AuthService.getAccessToken()).toBeNull();
+
+ AuthService.setAccessToken("tok");
+ expect(localStorage.getItem(TOKEN_KEY)).toEqual("tok");
+ expect(AuthService.getAccessToken()).toEqual("tok");
+
+ AuthService.removeAccessToken();
+ expect(AuthService.getAccessToken()).toBeNull();
+ });
+ });
+
+ describe("HTTP auth endpoints", () => {
+ it("register() POSTs username/password to the register endpoint", () => {
+ service.register("alice", "pw").subscribe();
+ const req = httpMock.expectOne(`${api}/${AuthService.REGISTER_ENDPOINT}`);
+ expect(req.request.method).toEqual("POST");
Review Comment:
The PR description / issue acceptance criteria mention exercising both success and error paths for the HTTP auth endpoints, but the current specs only cover the happy-path `flush({ accessToken: ... })` cases for `register()`, `auth()`, and `googleAuth()`. Add at least one failing-response test per endpoint (e.g., `req.flush(..., { status: 400/500, statusText: ... })`) and assert the observable rejects with an `HttpErrorResponse` so the error path is actually covered.
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(frontend): add unit tests for AuthService [texera]
Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan commented on code in PR #6470:
URL: https://github.com/apache/texera/pull/6470#discussion_r3607542685
##########
frontend/src/app/common/service/user/auth.service.spec.ts:
##########
@@ -0,0 +1,187 @@
+/**
+ * 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 { JwtHelperService } from "@auth0/angular-jwt";
+import { NzModalService } from "ng-zorro-antd/modal";
+import { AppSettings } from "../../app-setting";
+import { Role } from "../../type/user";
+import { AuthService, TOKEN_KEY } from "./auth.service";
+import { NotificationService } from "../notification/notification.service";
+import { GmailService } from "../gmail/gmail.service";
+import { GuiConfigService } from "../gui-config.service";
+
+describe("AuthService", () => {
+ let service: AuthService;
+ let httpMock: HttpTestingController;
+ let jwt: {
+ isTokenExpired: ReturnType<typeof vi.fn>;
+ decodeToken: ReturnType<typeof vi.fn>;
+ getTokenExpirationDate: ReturnType<typeof vi.fn>;
+ };
+ let notification: { error: ReturnType<typeof vi.fn> };
+ let config: { env: { inviteOnly: boolean } };
+ let modal: { info: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn> };
+
+ const api = AppSettings.getApiEndpoint();
+ const claims = {
+ role: Role.REGULAR,
+ userId: 5,
+ email: "u@x.com",
+ sub: "Ursula",
+ googleId: "g",
+ googleAvatar: "a",
+ comment: "c",
+ joiningReason: "r",
+ };
+
+ beforeEach(() => {
+ localStorage.clear();
+ jwt = {
+ isTokenExpired: vi.fn().mockReturnValue(false),
+ decodeToken: vi.fn().mockReturnValue(claims),
+ getTokenExpirationDate: vi.fn().mockReturnValue(new Date(Date.now() + 60_000)),
+ };
+ notification = { error: vi.fn() };
+ config = { env: { inviteOnly: false } };
+ modal = { info: vi.fn(), create: vi.fn() };
+
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [
+ AuthService,
+ { provide: JwtHelperService, useValue: jwt },
+ { provide: NotificationService, useValue: notification },
+ { provide: GmailService, useValue: {} },
+ { provide: GuiConfigService, useValue: config },
+ { provide: NzModalService, useValue: modal },
+ ],
+ });
+ service = TestBed.inject(AuthService);
+ httpMock = TestBed.inject(HttpTestingController);
+ });
+
+ afterEach(() => {
+ httpMock.verify();
+ localStorage.clear();
+ });
Review Comment:
fixed.
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(frontend): add unit tests for AuthService [texera]
Posted by "Ma77Ball (via GitHub)" <gi...@apache.org>.
Ma77Ball commented on PR #6470:
URL: https://github.com/apache/texera/pull/6470#issuecomment-4995877302
/request-review @aglinxinyuan
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(frontend): add unit tests for AuthService [texera]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6470:
URL: https://github.com/apache/texera/pull/6470#issuecomment-4990936818
## [Codecov](https://app.codecov.io/gh/apache/texera/pull/6470?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 70.23%. Comparing base ([`c7473a1`](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`2db7de7`](https://app.codecov.io/gh/apache/texera/commit/2db7de7e48f3f80c93f293a7ea4142b7c4918404?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #6470 +/- ##
============================================
+ Coverage 70.20% 70.23% +0.02%
Complexity 3390 3390
============================================
Files 1142 1142
Lines 44844 44844
Branches 4949 4949
============================================
+ Hits 31484 31494 +10
+ Misses 11725 11716 -9
+ Partials 1635 1634 -1
```
| [Flag](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| [access-control-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.00% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [agent-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.76% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [amber](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.68% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `9.97% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [config-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.30% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [file-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `65.63% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [frontend](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `69.03% <ø> (+0.06%)` | :arrow_up: | |
| [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.94% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [pyamber](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `91.19% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/6470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.14% <ø> (ø)` | | Carriedforward from [c7473a1](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/6470?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org