From e7724ab8a5f3aa61c361586e2904badfcc753079 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 14 Apr 2021 14:36:51 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20is=5Fprimary=20should=20d?= =?UTF-8?q?efault=20to=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/serializers/auth-method.js | 17 +++++++++++++++++ .../tests/unit/serializers/auth-method-test.js | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) 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: {}, }, ],