mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Remove readOnly attrs from Clients Count Config Serializer (#21391)
* octanify and add serialize false to readonly attrs * alphabetize * stuff * adds back payload.data check in normalizeResponse method of clients config serializer * test things * fix * clean up * Update ui/app/serializers/clients/config.js Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com> --------- Co-authored-by: Jordan Reimer <zofskeez@gmail.com> Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
This commit is contained in:
@@ -5,11 +5,17 @@
|
|||||||
|
|
||||||
import ApplicationSerializer from '../application';
|
import ApplicationSerializer from '../application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class ClientsConfigSerializer extends ApplicationSerializer {
|
||||||
|
// these attrs are readOnly
|
||||||
|
attrs = {
|
||||||
|
billingStartTimestamp: { serialize: false },
|
||||||
|
minimumRetentionMonths: { serialize: false },
|
||||||
|
reportingEnabled: { serialize: false },
|
||||||
|
};
|
||||||
|
|
||||||
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
||||||
if (!payload.data) {
|
if (!payload.data) {
|
||||||
// CBS TODO: Remove this if block once API is published
|
return super.normalizeResponse(...arguments);
|
||||||
return this._super(store, primaryModelClass, payload, id, requestType);
|
|
||||||
}
|
}
|
||||||
const normalizedPayload = {
|
const normalizedPayload = {
|
||||||
id: payload.id,
|
id: payload.id,
|
||||||
@@ -18,11 +24,11 @@ export default ApplicationSerializer.extend({
|
|||||||
enabled: payload.data.enabled?.includes('enable') ? 'On' : 'Off',
|
enabled: payload.data.enabled?.includes('enable') ? 'On' : 'Off',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return this._super(store, primaryModelClass, normalizedPayload, id, requestType);
|
return super.normalizeResponse(store, primaryModelClass, normalizedPayload, id, requestType);
|
||||||
},
|
}
|
||||||
|
|
||||||
serialize() {
|
serialize() {
|
||||||
const json = this._super(...arguments);
|
const json = super.serialize(...arguments);
|
||||||
if (json.enabled === 'On' || json.enabled === 'Off') {
|
if (json.enabled === 'On' || json.enabled === 'Off') {
|
||||||
const oldEnabled = json.enabled;
|
const oldEnabled = json.enabled;
|
||||||
json.enabled = oldEnabled === 'On' ? 'enable' : 'disable';
|
json.enabled = oldEnabled === 'On' ? 'enable' : 'disable';
|
||||||
@@ -33,5 +39,5 @@ export default ApplicationSerializer.extend({
|
|||||||
}
|
}
|
||||||
delete json.queries_available;
|
delete json.queries_available;
|
||||||
return json;
|
return json;
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
this.router = this.owner.lookup('service:router');
|
this.router = this.owner.lookup('service:router');
|
||||||
this.transitionStub = sinon.stub(this.router, 'transitionTo');
|
this.transitionStub = sinon.stub(this.router, 'transitionTo');
|
||||||
const store = this.owner.lookup('service:store');
|
const store = this.owner.lookup('service:store');
|
||||||
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 0) => {
|
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 24) => {
|
||||||
store.pushPayload('clients/config', {
|
store.pushPayload('clients/config', {
|
||||||
modelName: 'clients/config',
|
modelName: 'clients/config',
|
||||||
id: 'foo',
|
id: 'foo',
|
||||||
@@ -56,7 +56,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
|
|
||||||
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
||||||
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
||||||
const expected = { enabled: 'enable', retention_months: 5 };
|
const expected = { enabled: 'enable', retention_months: 24 };
|
||||||
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
@@ -80,11 +80,11 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
assert
|
assert
|
||||||
.dom('[data-test-inline-error-message]')
|
.dom('[data-test-inline-error-message]')
|
||||||
.hasText(
|
.hasText(
|
||||||
'Retention period must be greater than or equal to 0.',
|
'Retention period must be greater than or equal to 24.',
|
||||||
'Validation error shows for incorrect retention period'
|
'Validation error shows for incorrect retention period'
|
||||||
);
|
);
|
||||||
|
|
||||||
await fillIn('[data-test-input="retentionMonths"]', 5);
|
await fillIn('[data-test-input="retentionMonths"]', 24);
|
||||||
await click('[data-test-clients-config-save]');
|
await click('[data-test-clients-config-save]');
|
||||||
assert.dom('.modal.is-active').exists('Modal renders');
|
assert.dom('.modal.is-active').exists('Modal renders');
|
||||||
assert
|
assert
|
||||||
@@ -154,7 +154,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
|
|
||||||
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
||||||
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
||||||
const expected = { enabled: 'enable', retention_months: 5 };
|
const expected = { enabled: 'enable', retention_months: 24 };
|
||||||
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
@@ -165,8 +165,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
<div id="modal-wormhole"></div>
|
<div id="modal-wormhole"></div>
|
||||||
<Clients::Config @model={{this.model}} @mode="edit" />
|
<Clients::Config @model={{this.model}} @mode="edit" />
|
||||||
`);
|
`);
|
||||||
|
await fillIn('[data-test-input="retentionMonths"]', 24);
|
||||||
await fillIn('[data-test-input="retentionMonths"]', 5);
|
|
||||||
await click('[data-test-clients-config-save]');
|
await click('[data-test-clients-config-save]');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user