chore: add writeOnce field support

This commit is contained in:
Randall Morey committed 2022-01-20 17:20:24 -05:00
1 parent 1889dd0090
commit cd60c0bbc3
3 files changed
+8 -6

No files matched your search

@@ -73,14 +73,14 @@ export default class GeneratedHostCatalogModel extends BaseModel {
@attr('string', {
isNestedAttribute: true,
readOnly: true,
writeOnce: true,
description: '',
})
access_key_id;
@attr('string', {
isNestedAttribute: true,
readOnly: true,
writeOnce: true,
description: '',
})
secret_access_key;
@@ -107,14 +107,14 @@ export default class GeneratedHostCatalogModel extends BaseModel {
@attr('string', {
isNestedAttribute: true,
readOnly: true,
writeOnce: true,
description: '',
})
secret_id;
@attr('string', {
isNestedAttribute: true,
readOnly: true,
writeOnce: true,
description: '',
})
secret_value;
@@ -43,6 +43,8 @@ export default class ApplicationSerializer extends RESTSerializer {
if (type === 'string' && json[key] === '') json[key] = null;
// Do not serialize read-only attributes.
if (options.readOnly) delete json[key];
// Only serialize write-once fields on create.
if (options.writeOnce && !snapshot.record.isNew) delete json[key];
// Version is sent only if it has a non-nullish value
if (key === 'version') {
if (json[key] === null || json[key] === undefined) delete json[key];
@@ -40,7 +40,7 @@ module('Unit | Serializer | host catalog', function (hooks) {
assert.deepEqual(serializedRecord, expectedResult);
});
test('it serializes an AWS plugin as expected, ignoring read-only and Azure fields', async function (assert) {
test('it serializes an AWS plugin as expected, ignoring Azure fields', async function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-catalog');
@@ -76,7 +76,7 @@ module('Unit | Serializer | host catalog', function (hooks) {
assert.deepEqual(serializedRecord, expectedResult);
});
test('it serializes an Azure plugin as expected, ignoring read-only and Aws fields', async function (assert) {
test('it serializes an Azure plugin as expected, ignoring AWS fields', async function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-catalog');