Skip to content

Commit b9603d1

Browse files
committed
Auto merge of #2380 - Turbo87:missing-owner, r=locks
Fix owner invite error handling behavior Resolves #2084 r? @locks /cc @carols10cents
2 parents bbfddb0 + de37b0c commit b9603d1

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

app/adapters/crate.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ export default ApplicationAdapter.extend({
55
return this.ajax(this.urlForFollowAction(id), 'PUT');
66
},
77

8-
inviteOwner(id, username) {
9-
return this.ajax(this.urlForOwnerAction(id), 'PUT', {
8+
async inviteOwner(id, username) {
9+
let result = await this.ajax(this.urlForOwnerAction(id), 'PUT', {
1010
data: {
1111
owners: [username],
1212
},
1313
});
14+
15+
if (result.ok) {
16+
return result;
17+
} else {
18+
throw result;
19+
}
1420
},
1521

1622
removeOwner(id, username) {

mirage/route-handlers/crates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function register(server) {
165165
const user = schema.users.findBy({ login: ownerId });
166166

167167
if (!user) {
168-
return notFound();
168+
return { errors: [{ detail: `could not find user with login \`${ownerId}\`` }] };
169169
}
170170

171171
return { ok: true };

tests/acceptance/crate-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ module('Acceptance | crate page', function (hooks) {
281281
await fillIn('input[name="username"]', 'spookyghostboo');
282282
await click('[data-test-save-button]');
283283

284-
assert.dom('[data-test-error-message]').hasText('Error sending invite: Not Found');
284+
assert
285+
.dom('[data-test-error-message]')
286+
.hasText('Error sending invite: could not find user with login `spookyghostboo`');
285287
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
286288
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
287289
});

tests/models/crate-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module('Model | Crate', function (hooks) {
3333
let crateRecord = await this.store.findRecord('crate', crate.id);
3434

3535
await assert.rejects(crateRecord.inviteOwner('unknown'), function (error) {
36-
assert.deepEqual(error.errors, [{ detail: 'Not Found' }]);
37-
return error instanceof AdapterError;
36+
assert.deepEqual(error.errors, [{ detail: 'could not find user with login `unknown`' }]);
37+
return true;
3838
});
3939
});
4040
});

0 commit comments

Comments
 (0)