From 297ff762bd73edc86adbc98b60e3e5b92b6a181d Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 19 Aug 2021 19:12:05 +0200 Subject: [PATCH 1/3] mirage/crate-owner-invitation: Ensure `crate_id` is serialized as a number, not a string --- mirage/serializers/crate-owner-invitation.js | 2 ++ tests/mirage/me/crate-owner-invitations/list-test.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mirage/serializers/crate-owner-invitation.js b/mirage/serializers/crate-owner-invitation.js index 61c13dd4d0..b170756b63 100644 --- a/mirage/serializers/crate-owner-invitation.js +++ b/mirage/serializers/crate-owner-invitation.js @@ -22,6 +22,8 @@ export default BaseSerializer.extend({ 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; diff --git a/tests/mirage/me/crate-owner-invitations/list-test.js b/tests/mirage/me/crate-owner-invitations/list-test.js index 82a1e0b10d..41aa6cb733 100644 --- a/tests/mirage/me/crate-owner-invitations/list-test.js +++ b/tests/mirage/me/crate-owner-invitations/list-test.js @@ -49,7 +49,7 @@ 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', @@ -57,7 +57,7 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) { 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', From e7980cc16596145bfff486c5698b5ecc9ddbb894 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 19 Aug 2021 19:15:22 +0200 Subject: [PATCH 2/3] mirage/crate-owner-invitation: Include `invitee` in `users` list --- mirage/serializers/crate-owner-invitation.js | 2 +- tests/mirage/me/crate-owner-invitations/list-test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mirage/serializers/crate-owner-invitation.js b/mirage/serializers/crate-owner-invitation.js index b170756b63..9bf7fa3ccb 100644 --- a/mirage/serializers/crate-owner-invitation.js +++ b/mirage/serializers/crate-owner-invitation.js @@ -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); diff --git a/tests/mirage/me/crate-owner-invitations/list-test.js b/tests/mirage/me/crate-owner-invitations/list-test.js index 41aa6cb733..2ffa2afbd4 100644 --- a/tests/mirage/me/crate-owner-invitations/list-test.js +++ b/tests/mirage/me/crate-owner-invitations/list-test.js @@ -80,6 +80,13 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) { name: 'wycats', url: 'https://github.com/wycats', }, + { + avatar: user.avatar, + id: Number(user.id), + login: user.login, + name: user.name, + url: user.url, + }, ], }); }); From cb6c0fd50e78f87e27b7166b90f4b7a8c60d4eae Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 19 Aug 2021 19:17:41 +0200 Subject: [PATCH 3/3] mirage/crate-owner-invitation: Sort `users` by `id` --- mirage/serializers/crate-owner-invitation.js | 2 ++ .../mirage/me/crate-owner-invitations/list-test.js | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mirage/serializers/crate-owner-invitation.js b/mirage/serializers/crate-owner-invitation.js index 9bf7fa3ccb..85ec23bef0 100644 --- a/mirage/serializers/crate-owner-invitation.js +++ b/mirage/serializers/crate-owner-invitation.js @@ -15,6 +15,8 @@ export default BaseSerializer.extend({ this._adjust(hash); } + addToIncludes.sort((a, b) => a.id - b.id); + return [hash, addToIncludes]; }, diff --git a/tests/mirage/me/crate-owner-invitations/list-test.js b/tests/mirage/me/crate-owner-invitations/list-test.js index 2ffa2afbd4..6e4116819f 100644 --- a/tests/mirage/me/crate-owner-invitations/list-test.js +++ b/tests/mirage/me/crate-owner-invitations/list-test.js @@ -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), @@ -80,13 +87,6 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) { name: 'wycats', url: 'https://github.com/wycats', }, - { - avatar: user.avatar, - id: Number(user.id), - login: user.login, - name: user.name, - url: user.url, - }, ], }); });