Chore/cleanup filter attribute (#1500)

* refactor: 💡 Rename attributes called filter

* refactor: 💡 Remove adapter handling of old attribute errors

* refactor: 💡 Check for undefined in serializer instead of falsy
This commit is contained in:
Zhihe Li authored and GitHub committed 2022-12-02 13:44:11 -05:00
1 parent b1f14e5c62
commit f8429b15e9
11 files changed
+160 -53

No files matched your search

@@ -80,7 +80,7 @@ module('Unit | Serializer | host set', function (hooks) {
version: 1,
preferred_endpoints: [{ value: 'option 1' }, { value: 'option 2' }],
sync_interval_seconds: 1,
filter: 'filter 1 && filter 2',
filter_string: 'filter 1 && filter 2',
});
assert.deepEqual(record.serialize(), {
name: 'Host Set 1',
@@ -167,4 +167,47 @@ module('Unit | Serializer | host set', function (hooks) {
},
});
});
test('it normalizes filter correctly', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
const hostSetModelClass = store.createRecord('host-set').constructor;
const payload = {
id: '1',
name: 'Host Set 1',
type: 'plugin',
host_ids: ['1', '2', '3'],
preferred_endpoints: ['endpoint 1', 'endpoint 2'],
attributes: {
filter: 'filter',
},
};
const normalized = serializer.normalizeSingleResponse(
store,
hostSetModelClass,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'host-set',
attributes: {
type: 'plugin',
authorized_actions: [],
name: 'Host Set 1',
host_ids: ['1', '2', '3'],
preferred_endpoints: [
{ value: 'endpoint 1' },
{ value: 'endpoint 2' },
],
filters: [],
filter_string: 'filter',
},
relationships: {},
},
});
});
});
@@ -41,7 +41,7 @@ module('Unit | Serializer | Managed group', function (hooks) {
version: 1,
auth_method_id: '1234',
type: 'oidc',
filter: 'key=value',
filter_string: 'key=value',
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
@@ -73,7 +73,7 @@ module('Unit | Serializer | Managed group', function (hooks) {
version: undefined,
auth_method_id: '1234',
type: 'oidc',
filter: 'key=value',
filter_string: 'key=value',
},
},
});
@@ -134,7 +134,7 @@ module('Unit | Serializer | Managed group', function (hooks) {
version: 1,
auth_method_id: '1234',
type: 'oidc',
filter: 'key=value',
filter_string: 'key=value',
},
},
});
@@ -152,4 +152,45 @@ module('Unit | Serializer | Managed group', function (hooks) {
},
});
});
test('it normalizes correctly', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('managed-group');
const hostSetModelClass = store.createRecord('managed-group').constructor;
const payload = {
id: '1',
description: 'Description for the test',
version: 1,
auth_method_id: '1234',
type: 'oidc',
attributes: {
filter: 'key=value',
},
};
const normalized = serializer.normalizeSingleResponse(
store,
hostSetModelClass,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
attributes: {
type: 'oidc',
version: 1,
authorized_actions: [],
member_ids: [],
description: 'Description for the test',
auth_method_id: '1234',
filter_string: 'key=value',
},
type: 'managed-group',
relationships: {},
},
});
});
});