Skip to content

Commit

Permalink
Cleanup; documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Mar 28, 2023
1 parent 7ac24fe commit 8e907a9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion web/app/services/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion web/app/services/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
2 changes: 1 addition & 1 deletion web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions web/tests/acceptance/authenticated/dashboard-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
});
Expand Down
6 changes: 3 additions & 3 deletions web/tests/acceptance/authenticated/new/doc-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
});
Expand Down

0 comments on commit 8e907a9

Please sign in to comment.