chore: 🤖 Update serializer for storage buckets (#282)

This commit is contained in:
Zhihe Li authored and GitHub committed 2023-05-24 21:57:30 +00:00
1 parent 67a23a50fe
commit c63c95fd51
3 files changed
+63 -7

No files matched your search

+12 -3
View File
@@ -1,13 +1,22 @@
import ApplicationSerializer from './application';
export default class StorageBucketSerializer extends ApplicationSerializer {
serialize(snapshot) {
const serialized = super.serialize(...arguments);
if (!snapshot.record.isNew) {
delete serialized.bucket_name;
delete serialized.bucket_prefix;
}
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = structuredClone(hash);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove secret fields
delete normalized.data.attributes.access_key_id;
delete normalized.data.attributes.secret_access_key;
// Remove secret fields so we don't track them after creating/updating
normalized.data.attributes.access_key_id = null;
normalized.data.attributes.secret_access_key = null;
return normalized;
}
}
@@ -52,6 +52,53 @@ module('Unit | Serializer | storage bucket', function (hooks) {
assert.deepEqual(record.serialize(), expectedResult);
});
test('it serializes when updating correctly', async function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('storage-bucket');
store.push({
data: {
id: '1',
type: 'storage-bucket',
attributes: {
type: TYPE_STORAGE_BUCKET_PLUGIN,
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
name: 'AWS',
description: 'this has an aws plugin',
bucket_name: 'bucketname',
bucket_prefix: 'bucketprefix',
worker_filter: 'workerfilter',
region: 'eu-west-1',
access_key_id: 'foobars',
secret_access_key: 'testing',
secrets_hmac: 'hmac',
disable_credential_rotation: true,
version: 1,
},
},
});
const record = store.peekRecord('storage-bucket', '1');
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
const expectedResult = {
name: 'AWS',
description: 'this has an aws plugin',
type: TYPE_STORAGE_BUCKET_PLUGIN,
worker_filter: 'workerfilter',
attributes: {
region: 'eu-west-1',
disable_credential_rotation: true,
},
secrets: {
access_key_id: 'foobars',
secret_access_key: 'testing',
},
version: 1,
};
assert.deepEqual(serializedRecord, expectedResult);
});
test('it normalizes correctly', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
@@ -94,6 +141,8 @@ module('Unit | Serializer | storage bucket', function (hooks) {
secrets_hmac: 'this is secret',
region: 'eu-west-1',
disable_credential_rotation: true,
access_key_id: null,
secret_access_key: null,
},
type: 'storage-bucket',
relationships: {},
@@ -111,10 +111,8 @@ module('Acceptance | storage-buckets | update', function (hooks) {
await click(SAVE_BUTTON_SELECTOR, 'Click save');
assert.dom(SECRET_FIELD_BUTTON_SELECTOR).isDisabled();
assert.dom(ACCESS_KEY_ID_FIELD_SELECTOR).hasValue(ACCESS_KEY_ID_FIELD_TEXT);
assert
.dom(SECRET_ACCESS_KEY_FIELD_SELECTOR)
.hasValue(SECRET_ACCESS_KEY_FIELD_TEXT);
assert.dom(ACCESS_KEY_ID_FIELD_SELECTOR).hasNoValue();
assert.dom(SECRET_ACCESS_KEY_FIELD_SELECTOR).hasNoValue();
});
test('can cancel changes to access key fields', async function (assert) {