Skip to content

Commit 2ea5d41

Browse files
committed
Auto merge of #3490 - Turbo87:fix-invites, r=pietroalbini
CrateOwnerInvite: Avoid "missing `id`" issue Ember Data expects all resources to have an `id`. In this serializer we are renaming that expectation to `crate_id` for questionable reasons. This worked fine as long as only `CrateOwnerInvite` resources were contained in the response, but now we also have `User` resources, and those don't have a `crate_id` attribute, which is causing issues. This commit removes the `users` array from the response for now to fix this problem. In the future we should look into either responding with a proper ID or generating it based on `crate_id` and `invitee_id`.
2 parents 9fd121d + 0d74ef4 commit 2ea5d41

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

app/serializers/crate-owner-invite.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ export default class CrateOwnerInviteSerializer extends ApplicationSerializer {
1010
payloadKeyFromModelName() {
1111
return 'crate_owner_invite';
1212
}
13+
14+
normalizeResponse(store, schema, payload, id, requestType) {
15+
if (payload.users) {
16+
delete payload.users;
17+
}
18+
19+
return super.normalizeResponse(store, schema, payload, id, requestType);
20+
}
1321
}

tests/acceptance/invites-test.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,32 @@ module('Acceptance | /me/pending-invites', function (hooks) {
1515
let user = context.server.create('user');
1616
context.authenticateAs(user);
1717

18-
context.server.get('/api/v1/me/crate_owner_invitations', {
19-
crate_owner_invitations: [
20-
{
21-
invited_by_username: 'janed',
22-
crate_name: 'nanomsg',
23-
crate_id: 42,
24-
created_at: '2016-12-24T12:34:56Z',
25-
},
26-
{
27-
invited_by_username: 'wycats',
28-
crate_name: 'ember-rs',
29-
crate_id: 1,
30-
created_at: '2020-12-31T12:34:56Z',
31-
},
32-
],
18+
let inviter = context.server.create('user', { name: 'janed' });
19+
let inviter2 = context.server.create('user', { name: 'wycats' });
20+
context.server.get('/api/v1/me/crate_owner_invitations', function () {
21+
let users = [this.serialize(inviter, 'user').user, this.serialize(inviter2, 'user').user];
22+
23+
return {
24+
crate_owner_invitations: [
25+
{
26+
invited_by_username: 'janed',
27+
crate_name: 'nanomsg',
28+
crate_id: 42,
29+
created_at: '2016-12-24T12:34:56Z',
30+
invitee_id: parseInt(user.id, 10),
31+
inviter_id: parseInt(inviter.id, 10),
32+
},
33+
{
34+
invited_by_username: 'wycats',
35+
crate_name: 'ember-rs',
36+
crate_id: 1,
37+
created_at: '2020-12-31T12:34:56Z',
38+
invitee_id: parseInt(user.id, 10),
39+
inviter_id: parseInt(inviter2.id, 10),
40+
},
41+
],
42+
users,
43+
};
3344
});
3445
}
3546

0 commit comments

Comments
 (0)