From 8e907a915945169938897c6e6bc0d9600e2ab032 Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Tue, 28 Mar 2023 11:04:56 -0400 Subject: [PATCH] Cleanup; documentation --- web/app/services/fetch.ts | 5 ++++- web/app/services/session.ts | 13 ++++++++++++- web/mirage/config.ts | 2 +- .../acceptance/authenticated/dashboard-test.ts | 4 ++-- web/tests/acceptance/authenticated/new/doc-test.ts | 6 +++--- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/web/app/services/fetch.ts b/web/app/services/fetch.ts index cc47b7112..fff0a02f0 100644 --- a/web/app/services/fetch.ts +++ b/web/app/services/fetch.ts @@ -27,7 +27,10 @@ export default class FetchService extends Service { try { const resp = await fetch(url, options); - this.session.pollResponseIs401 = resp.status === 401 && isPollCall; + // if it's a poll call, tell the SessionService if the response was a 401 + if (isPollCall) { + this.session.pollResponseIs401 = resp.status === 401; + } if (!resp.ok) { if (resp.status === 401) { diff --git a/web/app/services/session.ts b/web/app/services/session.ts index 475ea9220..0adef14b9 100644 --- a/web/app/services/session.ts +++ b/web/app/services/session.ts @@ -17,13 +17,24 @@ export default class SessionService extends EmberSimpleAuthSessionService { @service declare session: SessionService; @service declare flashMessages: FlashMessageService; + /** + * Whether the current session is valid. + * Set false if our poll response is 401, and when the + * user requires authentication with EmberSimpleAuth. + */ + @tracked tokenIsValid = true; + /** * Whether the service should show a reauthentication message. * True when the user has dismissed a previous re-auth message. */ @tracked preventReauthenticationMessage = false; - @tracked tokenIsValid = true; + + /** + * Whether the last poll response was a 401. + * Updated by the fetch service on every pollCall. + */ @tracked pollResponseIs401 = false; /** diff --git a/web/mirage/config.ts b/web/mirage/config.ts index 5e97f67f0..5bb606424 100644 --- a/web/mirage/config.ts +++ b/web/mirage/config.ts @@ -142,7 +142,7 @@ export default function (mirageConfig) { * Used by the AuthenticatedUserService to get the user's profile. */ this.get("https://www.googleapis.com/userinfo/v2/me", (schema) => { - // If the test has set a user, return it. + // If the test has explicitly set a user, return it. if (schema.mes.first()) { return schema.mes.first().attrs; } else { diff --git a/web/tests/acceptance/authenticated/dashboard-test.ts b/web/tests/acceptance/authenticated/dashboard-test.ts index d687a18ac..5d7912369 100644 --- a/web/tests/acceptance/authenticated/dashboard-test.ts +++ b/web/tests/acceptance/authenticated/dashboard-test.ts @@ -5,7 +5,7 @@ import { authenticateSession } from "ember-simple-auth/test-support"; import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support"; import { getPageTitle } from "ember-page-title/test-support"; -interface AuthenticatedDashboardRouteTestContext extends MirageTestContext {} +interface AllRouteContext extends MirageTestContext {} module("Acceptance | authenticated/dashboard", function (hooks) { setupApplicationTest(hooks); @@ -15,7 +15,7 @@ module("Acceptance | authenticated/dashboard", function (hooks) { authenticateSession({}); }); - test("the page title is correct", async function (this: AuthenticatedDashboardRouteTestContext, assert) { + test("the page title is correct", async function (this: AllRouteContext, assert) { await visit("/dashboard"); assert.equal(getPageTitle(), "Dashboard | Hermes"); }); diff --git a/web/tests/acceptance/authenticated/new/doc-test.ts b/web/tests/acceptance/authenticated/new/doc-test.ts index cdaafda16..4e27f1644 100644 --- a/web/tests/acceptance/authenticated/new/doc-test.ts +++ b/web/tests/acceptance/authenticated/new/doc-test.ts @@ -5,7 +5,7 @@ import { authenticateSession } from "ember-simple-auth/test-support"; import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support"; import { getPageTitle } from "ember-page-title/test-support"; -interface AuthenticatedNewDocRouteTestContext extends MirageTestContext {} +interface AllRouteContext extends MirageTestContext {} module("Acceptance | authenticated/new", function (hooks) { setupApplicationTest(hooks); @@ -15,12 +15,12 @@ module("Acceptance | authenticated/new", function (hooks) { authenticateSession({}); }); - test("the page title is correct (RFC)", async function (this: AuthenticatedNewDocRouteTestContext, assert) { + test("the page title is correct (RFC)", async function (this: AllRouteContext, assert) { await visit("/new/doc?docType=RFC"); assert.equal(getPageTitle(), "Create Your RFC | Hermes"); }); - test("the page title is correct (PRD)", async function (this: AuthenticatedNewDocRouteTestContext, assert) { + test("the page title is correct (PRD)", async function (this: AllRouteContext, assert) { await visit("/new/doc?docType=PRD"); assert.equal(getPageTitle(), "Create Your PRD | Hermes"); });