fix: 🐛 API sends is_primary, not primary

This commit is contained in:
Randall Morey committed 2021-04-14 11:28:07 -04:00
1 parent c213ee18b2
commit deb8871060
6 files changed
+10 -9

No files matched your search

@@ -11,7 +11,7 @@ export default class GeneratedAuthMethodModel extends BaseModel {
description: 'Specifies if this is the primary auth method for its scope.',
readOnly: true,
})
primary;
is_primary;
@attr('string', {
description: 'The type of the resource, to help differentiate schemas',
+1 -1
View File
@@ -7,7 +7,7 @@ export default class AuthMethodModel extends GeneratedAuthMethodModel {
/**
* @type {boolean}
*/
@equal('primary', true) isPrimary;
@equal('is_primary', true) isPrimary;
/**
* @type {boolean}
+3 -3
View File
@@ -2,8 +2,8 @@ import ApplicationSerializer from './application';
export default class AuthMethodSerializer extends ApplicationSerializer {
/**
* Sorts the array in order of "primary" such that the primary method appears
* first. The "natural" order of auth methods places primary first.
* Sorts the array in order of "is_primary" such that the primary method
* appears first. The "natural" order of auth methods places primary first.
*
* @override
* @return {object}
@@ -11,7 +11,7 @@ export default class AuthMethodSerializer extends ApplicationSerializer {
normalizeArrayResponse() {
const normalized = super.normalizeArrayResponse(...arguments);
normalized.data = normalized.data.sort((a) =>
a.attributes.primary ? -1 : 1
a.attributes.is_primary ? -1 : 1
);
return normalized;
}
+1 -1
View File
@@ -12,7 +12,7 @@ export default ApplicationSerializer.extend({
// as such with a read-only boolean field (this is how the API behaves).
const isPrimary =
model.scope && model.scope.primaryAuthMethodId === model.id;
json.primary = isPrimary;
json.is_primary = isPrimary;
return json;
},
});
@@ -27,14 +27,14 @@ module('Unit | Serializer | auth method', function (hooks) {
const serializer = store.serializerFor('auth-method');
const modelClass = store.createRecord('auth-method').constructor;
const payload = {
items: [{ id: 1 }, { id: 2, primary: true }, { id: 3 }],
items: [{ id: 1 }, { id: 2, is_primary: true }, { id: 3 }],
};
const normalizedArray = serializer.normalizeArrayResponse(
store,
modelClass,
payload
);
assert.ok(payload.items[1].primary, 'Second payload item is primary');
assert.ok(payload.items[1].is_primary, 'Second payload item is primary');
assert.deepEqual(
normalizedArray,
{
@@ -43,7 +43,7 @@ module('Unit | Serializer | auth method', function (hooks) {
{
id: '2',
type: 'auth-method',
attributes: { primary: true },
attributes: { is_primary: true },
relationships: {},
},
{
+1
View File
@@ -83,6 +83,7 @@ module.exports = function (environment) {
'ember-cli-mirage': {
directory: '../../addons/api/mirage',
enabled: false,
},
featureFlags: {