diff --git a/addons/api/addon/serializers/auth-method.js b/addons/api/addon/serializers/auth-method.js index ff3bdc5ed..a8569c14d 100644 --- a/addons/api/addon/serializers/auth-method.js +++ b/addons/api/addon/serializers/auth-method.js @@ -15,4 +15,21 @@ export default class AuthMethodSerializer extends ApplicationSerializer { ); return normalized; } + + /** + * Sets `is_primary` to `false` if it is missing in the response. The API + * omits "zero" values per: + * https://developers.google.com/protocol-buffers/docs/proto3#default + * + * TODO: generalize this so that all zero values are reified. + * @override + * @return {object} + */ + normalize() { + const normalized = super.normalize(...arguments); + if (!normalized.data.attributes.is_primary) { + normalized.data.attributes.is_primary = false; + } + return normalized; + } } diff --git a/addons/api/tests/unit/serializers/auth-method-test.js b/addons/api/tests/unit/serializers/auth-method-test.js index 2e7494762..cd7fcd396 100644 --- a/addons/api/tests/unit/serializers/auth-method-test.js +++ b/addons/api/tests/unit/serializers/auth-method-test.js @@ -49,13 +49,13 @@ module('Unit | Serializer | auth method', function (hooks) { { id: '1', type: 'auth-method', - attributes: {}, + attributes: { is_primary: false }, relationships: {}, }, { id: '3', type: 'auth-method', - attributes: {}, + attributes: { is_primary: false }, relationships: {}, }, ],