Skip to content

Commit

Permalink
Auto merge of #3869 - Turbo87:invitations, r=hi-rustin
Browse files Browse the repository at this point in the history
mirage/crate-owner-invitation: Adjust fake API to match the real API

#3763 changed a few minor things about the crate owner invitations responses. This PR adjusts our mirage code to match these changes (excluding pagination).
  • Loading branch information
bors committed Aug 29, 2021
2 parents 640e96c + cb6c0fd commit 9fc0045
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion mirage/serializers/crate-owner-invitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BaseSerializer from './application';

export default BaseSerializer.extend({
// eslint-disable-next-line ember/avoid-leaking-state-in-ember-objects
include: ['inviter'],
include: ['inviter', 'invitee'],

getHashForResource() {
let [hash, addToIncludes] = BaseSerializer.prototype.getHashForResource.apply(this, arguments);
Expand All @@ -15,13 +15,17 @@ export default BaseSerializer.extend({
this._adjust(hash);
}

addToIncludes.sort((a, b) => a.id - b.id);

return [hash, addToIncludes];
},

_adjust(hash) {
delete hash.id;
delete hash.token;

hash.crate_id = Number(hash.crate_id);

let crate = this.schema.crates.find(hash.crate_id);
hash.crate_name = crate.name;

Expand Down
11 changes: 9 additions & 2 deletions tests/mirage/me/crate-owner-invitations/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) {
assert.deepEqual(await response.json(), {
crate_owner_invitations: [
{
crate_id: nanomsg.id,
crate_id: Number(nanomsg.id),
crate_name: 'nanomsg',
created_at: '2016-12-24T12:34:56Z',
invited_by_username: 'janed',
invitee_id: Number(user.id),
inviter_id: Number(inviter.id),
},
{
crate_id: ember.id,
crate_id: Number(ember.id),
crate_name: 'ember-rs',
created_at: '2020-12-31T12:34:56Z',
invited_by_username: 'wycats',
Expand All @@ -66,6 +66,13 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) {
},
],
users: [
{
avatar: user.avatar,
id: Number(user.id),
login: user.login,
name: user.name,
url: user.url,
},
{
avatar: 'https://avatars1.githubusercontent.com/u/14631425?v=4',
id: Number(inviter.id),
Expand Down

0 comments on commit 9fc0045

Please sign in to comment.