Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions app/controllers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ const BASE_URL = APPS.API_BACKEND;

export default class ProfileController extends Controller {
@service toast;
@service router;
get isDev() {
if (
this.router.currentRoute &&
this.router.currentRoute.queryParams.dev === 'true'
) {
return this.router.currentRoute.queryParams.dev;
}
return false;
}

get imageUploadUrl() {
return `${BASE_URL}/users/picture`;
}
Expand Down
7 changes: 1 addition & 6 deletions app/routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ const BASE_URL = APPS.API_BACKEND;
export default class ProfileRoute extends Route {
@service toast;
@service fastboot;
@service router;
beforeModel(transition) {
if (transition?.to?.queryParams?.dev !== 'true') {
this.router.transitionTo('/page-not-found');
}
}

async model() {
try {
const res = await fetch(`${BASE_URL}/users/isDeveloper`, {
Expand Down
25 changes: 3 additions & 22 deletions tests/unit/routes/profile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,15 @@ module('Unit | Route | profile', function (hooks) {
hooks.beforeEach(function () {
this.fetchStub = sinon.stub(window, 'fetch');
this.route = this.owner.lookup('route:profile');
sinon.stub(this.route.router, 'transitionTo');
});

hooks.afterEach(function () {
this.fetchStub.restore();
sinon.restore();
});

test('redirects to 404 page if dev flag is not present', function (assert) {
const transition = { to: { queryParams: { dev: 'false' } } };

this.route.beforeModel(transition);

assert.ok(
this.route.router.transitionTo.calledOnceWith('/page-not-found'),
'Redirected to /page-not-found when dev is not true',
);
});

test('allows access when dev flag is true', function (assert) {
const transition = { to: { queryParams: { dev: 'true' } } };

this.route.beforeModel(transition);

assert.ok(
this.route.router.transitionTo.notCalled,
'No redirection occurs when dev query param is true',
);
test('profile route exists and is accessible', function (assert) {
let route = this.owner.lookup('route:profile');
assert.ok(route, 'Test the route exists and is accessible');
});

test('it fetches and transforms model data correctly', async function (assert) {
Expand Down