Skip to content

Commit

Permalink
Force config loading at application root
Browse files Browse the repository at this point in the history
  • Loading branch information
jabrah committed Feb 27, 2024
1 parent 6445cf0 commit eb9f4d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export default class ApplicationRoute extends CheckSessionRoute {
* If there is a userToken query parameter call the user service with that parameter
* to ensure objects are updated in the backend before any queries are done.
*/
beforeModel(transition) {
async beforeModel(transition) {
let userToken = transition.to.queryParams.userToken;

if (!this.staticConfig.config) {
await this.staticConfig.setupStaticConfig();
}

if (userToken) {
return fetch(`/user/whoami?userToken=${encodeURIComponent(userToken)}`);
}
Expand All @@ -39,9 +43,5 @@ export default class ApplicationRoute extends CheckSessionRoute {
if (loader) {
loader.style.display = 'none';
}

if (!this.staticConfig.config) {
await this.staticConfig.setupStaticConfig();
}
}
}
1 change: 1 addition & 0 deletions app/routes/check-session-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class CheckSessionRouteRoute extends Route {

@action
async error(error, transition) {
console.error(error);
const errorObject = error?.errors?.firstObject || {};

if ([401, 403].includes(Number(errorObject.status))) {
Expand Down
27 changes: 27 additions & 0 deletions tests/acceptance/app-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable ember/no-classic-classes, ember/prefer-ember-test-helpers, ember/require-valid-css-selector-in-test-helpers */
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';
import { authenticateSession } from 'ember-simple-auth/test-support';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import sharedScenario from '../../mirage/scenarios/shared';

module('Acceptance | application', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(async function () {
await authenticateSession({ user: { id: '0' } });
});

test('Make sure app loads outside of root', async function (assert) {
sharedScenario(this.server);

await visit('/app/submissions');

assert.dom('.lds-dual-ring').doesNotExist('Loading spinner should not be present');

assert.dom('h1').exists();
assert.dom('h1').includesText('Submission');
});
});

0 comments on commit eb9f4d7

Please sign in to comment.