|
| 1 | +import { module, test } from 'qunit'; |
| 2 | + |
| 3 | +import fetch from 'fetch'; |
| 4 | + |
| 5 | +import { setupTest } from '../../helpers'; |
| 6 | +import setupMirage from '../../helpers/setup-mirage'; |
| 7 | + |
| 8 | +module('Mirage | /me', function (hooks) { |
| 9 | + setupTest(hooks); |
| 10 | + setupMirage(hooks); |
| 11 | + |
| 12 | + module('PUT /api/v1/confirm/:token', function () { |
| 13 | + test('returns `ok: true` for a known token (unauthenticated)', async function (assert) { |
| 14 | + let user = this.server.create('user', { emailVerificationToken: 'foo' }); |
| 15 | + assert.strictEqual(user.emailVerified, false); |
| 16 | + |
| 17 | + let response = await fetch('/api/v1/confirm/foo', { method: 'PUT' }); |
| 18 | + assert.equal(response.status, 200); |
| 19 | + |
| 20 | + let responsePayload = await response.json(); |
| 21 | + assert.deepEqual(responsePayload, { ok: true }); |
| 22 | + |
| 23 | + user.reload(); |
| 24 | + assert.strictEqual(user.emailVerified, true); |
| 25 | + }); |
| 26 | + |
| 27 | + test('returns `ok: true` for a known token (authenticated)', async function (assert) { |
| 28 | + let user = this.server.create('user', { emailVerificationToken: 'foo' }); |
| 29 | + assert.strictEqual(user.emailVerified, false); |
| 30 | + |
| 31 | + this.server.create('mirage-session', { user }); |
| 32 | + |
| 33 | + let response = await fetch('/api/v1/confirm/foo', { method: 'PUT' }); |
| 34 | + assert.equal(response.status, 200); |
| 35 | + |
| 36 | + let responsePayload = await response.json(); |
| 37 | + assert.deepEqual(responsePayload, { ok: true }); |
| 38 | + |
| 39 | + user.reload(); |
| 40 | + assert.strictEqual(user.emailVerified, true); |
| 41 | + }); |
| 42 | + |
| 43 | + test('returns an error for unknown tokens', async function (assert) { |
| 44 | + let response = await fetch('/api/v1/confirm/unknown', { method: 'PUT' }); |
| 45 | + assert.equal(response.status, 400); |
| 46 | + |
| 47 | + let responsePayload = await response.json(); |
| 48 | + assert.deepEqual(responsePayload, { |
| 49 | + errors: [{ detail: 'Email belonging to token not found.' }], |
| 50 | + }); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments