Skip to content

Commit

Permalink
refactor(mon-pix): add unit test for reset password route
Browse files Browse the repository at this point in the history
for handling a server error case
  • Loading branch information
er-lim authored Nov 6, 2024
1 parent 95a62c2 commit 61445b7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mon-pix/tests/unit/routes/reset-password-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Service from '@ember/service';
import { t } from 'ember-intl/test-support';
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';
import sinon from 'sinon';

import setupIntl from '../../helpers/setup-intl';

module('Unit | Route | reset-password', function (hooks) {
setupTest(hooks);
setupIntl(hooks);

module('Route behavior', function (hooks) {
let storeStub;
Expand Down Expand Up @@ -78,5 +82,31 @@ module('Unit | Route | reset-password', function (hooks) {
assert.deepEqual(result.temporaryKey, params.temporary_key);
});
});
module('when password reset demand is not valid', function () {
module('when error status is equal to 401', function () {
test('it adds an error in errors service and replace current route with "reset-password-demand"', async function (assert) {
// given
const errors = [{ status: 401 }];
const errorsService = this.owner.lookup('service:errors');
const route = this.owner.lookup('route:reset-password');
const replaceWithStub = sinon.stub();
const routerStub = Service.create({
replaceWith: replaceWithStub,
});

queryRecordStub.rejects({ errors });
route.set('store', storeStub);
route.set('router', routerStub);

// when
await route.model(params);

// then
sinon.assert.calledOnceWithExactly(replaceWithStub, 'password-reset-demand');
assert.strictEqual(errorsService.errors.length, 1);
assert.strictEqual(errorsService.errors[0], t('pages.reset-password.error.expired-demand'));
});
});
});
});
});

0 comments on commit 61445b7

Please sign in to comment.