Merge pull request #128 from hashicorp/chore-version

chore: 🤖 all resources should have a version
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2020-08-21 13:28:34 -04:00
commit 246e8ef2a1
7 files changed
+52

No files matched your search

@@ -39,4 +39,9 @@ export default class GeneratedAuthMethodModel extends BaseModel {
})
disabled;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
@@ -33,4 +33,10 @@ export default class GeneratedGroupModel extends BaseModel {
description: 'Whether the resource is disabled',
})
disabled;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
@@ -38,4 +38,9 @@ export default class GeneratedHostCatalogModel extends BaseModel {
description: 'Attributes specific to the catalog type'
}) attributes;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
@@ -34,4 +34,9 @@ export default class GeneratedScopeModel extends BaseModel {
})
updated_time;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
@@ -33,4 +33,9 @@ export default class GeneratedUserModel extends BaseModel {
description: 'Whether the resource is disabled',
})
disabled;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
@@ -40,6 +40,10 @@ export default class ApplicationSerializer extends RESTSerializer {
let value = super.serializeAttribute(...arguments);
// Do not serialize read-only attributes.
if (options.readOnly) 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];
}
// Do not serialize `disabled` fields.
// TODO: disabled is temporarily disabled
if (key === 'disabled') delete json[key];
@@ -29,6 +29,28 @@ module('Unit | Serializer | application', function (hooks) {
});
});
test('it serializes non-nullish version fields', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const record = store.createRecord('user', {
name: 'User',
description: 'Description',
version: null
});
let serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
name: 'User',
description: 'Description'
});
record.version = 1;
serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
name: 'User',
description: 'Description',
version: 1
});
});
test('it normalizes array records from an `items` root key', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');