Skip to content

Commit f269d98

Browse files
committed
tests/acceptance/email-change: Migrate from mirage to @crates-io/msw
1 parent 5066f6b commit f269d98

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

tests/acceptance/email-change-test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { click, currentURL, fillIn } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

4+
import { http, HttpResponse } from 'msw';
5+
46
import { setupApplicationTest } from 'crates-io/tests/helpers';
57

68
import { visit } from '../helpers/visit-ignoring-abort';
79

810
module('Acceptance | Email Change', function (hooks) {
9-
setupApplicationTest(hooks);
11+
setupApplicationTest(hooks, { msw: true });
1012

1113
test('happy path', async function (assert) {
12-
let user = this.server.create('user', { email: '[email protected]' });
14+
let user = this.db.user.create({ email: '[email protected]' });
1315

1416
this.authenticateAs(user);
1517

@@ -43,14 +45,14 @@ module('Acceptance | Email Change', function (hooks) {
4345
assert.dom('[data-test-email-input] [data-test-verification-sent]').exists();
4446
assert.dom('[data-test-email-input] [data-test-resend-button]').isEnabled();
4547

46-
user.reload();
48+
user = this.db.user.findFirst({ where: { id: { equals: user.id } } });
4749
assert.strictEqual(user.email, '[email protected]');
4850
assert.false(user.emailVerified);
4951
assert.ok(user.emailVerificationToken);
5052
});
5153

5254
test('happy path with `email: null`', async function (assert) {
53-
let user = this.server.create('user', { email: undefined });
55+
let user = this.db.user.create({ email: undefined });
5456

5557
this.authenticateAs(user);
5658

@@ -80,14 +82,14 @@ module('Acceptance | Email Change', function (hooks) {
8082
assert.dom('[data-test-email-input] [data-test-verification-sent]').exists();
8183
assert.dom('[data-test-email-input] [data-test-resend-button]').isEnabled();
8284

83-
user.reload();
85+
user = this.db.user.findFirst({ where: { id: { equals: user.id } } });
8486
assert.strictEqual(user.email, '[email protected]');
8587
assert.false(user.emailVerified);
8688
assert.ok(user.emailVerificationToken);
8789
});
8890

8991
test('cancel button', async function (assert) {
90-
let user = this.server.create('user', { email: '[email protected]' });
92+
let user = this.db.user.create({ email: '[email protected]' });
9193

9294
this.authenticateAs(user);
9395

@@ -102,18 +104,18 @@ module('Acceptance | Email Change', function (hooks) {
102104
assert.dom('[data-test-email-input] [data-test-not-verified]').doesNotExist();
103105
assert.dom('[data-test-email-input] [data-test-verification-sent]').doesNotExist();
104106

105-
user.reload();
107+
user = this.db.user.findFirst({ where: { id: { equals: user.id } } });
106108
assert.strictEqual(user.email, '[email protected]');
107109
assert.true(user.emailVerified);
108110
assert.notOk(user.emailVerificationToken);
109111
});
110112

111113
test('server error', async function (assert) {
112-
let user = this.server.create('user', { email: '[email protected]' });
114+
let user = this.db.user.create({ email: '[email protected]' });
113115

114116
this.authenticateAs(user);
115117

116-
this.server.put('/api/v1/users/:user_id', {}, 500);
118+
this.worker.use(http.put('/api/v1/users/:user_id', () => HttpResponse.json({}, { status: 500 })));
117119

118120
await visit('/settings/profile');
119121
await click('[data-test-email-input] [data-test-edit-button]');
@@ -126,15 +128,15 @@ module('Acceptance | Email Change', function (hooks) {
126128
.dom('[data-test-notification-message="error"]')
127129
.hasText('Error in saving email: An unknown error occurred while saving this email.');
128130

129-
user.reload();
131+
user = this.db.user.findFirst({ where: { id: { equals: user.id } } });
130132
assert.strictEqual(user.email, '[email protected]');
131133
assert.true(user.emailVerified);
132134
assert.notOk(user.emailVerificationToken);
133135
});
134136

135137
module('Resend button', function () {
136138
test('happy path', async function (assert) {
137-
let user = this.server.create('user', { email: '[email protected]', emailVerificationToken: 'secret123' });
139+
let user = this.db.user.create({ email: '[email protected]', emailVerificationToken: 'secret123' });
138140

139141
this.authenticateAs(user);
140142

@@ -152,11 +154,11 @@ module('Acceptance | Email Change', function (hooks) {
152154
});
153155

154156
test('server error', async function (assert) {
155-
let user = this.server.create('user', { email: '[email protected]', emailVerificationToken: 'secret123' });
157+
let user = this.db.user.create({ email: '[email protected]', emailVerificationToken: 'secret123' });
156158

157159
this.authenticateAs(user);
158160

159-
this.server.put('/api/v1/users/:user_id/resend', {}, 500);
161+
this.worker.use(http.put('/api/v1/users/:user_id/resend', () => HttpResponse.json({}, { status: 500 })));
160162

161163
await visit('/settings/profile');
162164
assert.strictEqual(currentURL(), '/settings/profile');

0 commit comments

Comments
 (0)