UI: Add validation for activity counter config retention_months max (#27429)

This commit is contained in:
claire bontempo
2024-06-11 08:08:47 -07:00
committed by GitHub
parent 927da859f7
commit 55547fb81d
4 changed files with 48 additions and 38 deletions

View File

@@ -15,6 +15,10 @@ const validations = {
message: (model) =>
`Retention period must be greater than or equal to ${model.minimumRetentionMonths}.`,
},
{
validator: (model) => parseInt(model.retentionMonths) <= 60,
message: 'Retention period must be less than or equal to 60.',
},
],
};

View File

@@ -4,7 +4,6 @@
*/
import {
add,
addMonths,
differenceInCalendarMonths,
endOfMonth,
@@ -37,7 +36,6 @@ export const CONFIG_RESPONSE = {
request_id: 'some-config-id',
data: {
billing_start_timestamp: formatRFC3339(LICENSE_START),
default_report_months: 12,
enabled: 'default-enabled',
minimum_retention_months: 48,
queries_available: false,
@@ -251,41 +249,41 @@ export default function (server) {
// we don't currently use build_date, including for accuracy. it's only tracked in versions >= 1.11.0
build_date: null,
previous_version: null,
timestamp_installed: LICENSE_START.toISOString(),
timestamp_installed: '2023-07-02T00:00:00Z',
},
'1.9.1': {
build_date: null,
previous_version: '1.9.0',
timestamp_installed: addMonths(LICENSE_START, 1).toISOString(),
timestamp_installed: '2023-08-02T00:00:00Z',
},
// auth mount attribution added in 1.10.0
'1.10.1': {
build_date: null,
previous_version: '1.9.1',
timestamp_installed: addMonths(LICENSE_START, 2).toISOString(), // same as UPGRADE_DATE
timestamp_installed: '2023-09-02T00:00:00Z', // same as UPGRADE_DATE
},
'1.10.3': {
build_date: null,
previous_version: '1.10.1',
timestamp_installed: add(LICENSE_START, { months: 2, weeks: 3 }).toISOString(),
timestamp_installed: '2023-10-23T00:00:00Z',
},
// no notable UI changes
'1.14.4': {
build_date: addMonths(LICENSE_START, 3).toISOString(),
build_date: '2023-11-02T00:00:00Z',
previous_version: '1.10.3',
timestamp_installed: addMonths(LICENSE_START, 3).toISOString(),
timestamp_installed: '2023-11-02T00:00:00Z',
},
// sync clients added
'1.16.0': {
build_date: addMonths(LICENSE_START, 4).toISOString(),
build_date: '2023-11-23T00:00:00Z',
previous_version: '1.14.4',
timestamp_installed: addMonths(LICENSE_START, 4).toISOString(),
timestamp_installed: '2023-11-23T00:00:00Z',
},
// acme_clients separated from non-entity clients
'1.17.0': {
build_date: addMonths(LICENSE_START, 5).toISOString(),
build_date: '2023-12-02T00:00:00Z',
previous_version: '1.16.0',
timestamp_installed: addMonths(LICENSE_START, 5).toISOString(),
timestamp_installed: '2023-12-02T00:00:00Z',
},
},
},

View File

@@ -18,7 +18,7 @@ module('Integration | Component | client count config', function (hooks) {
this.router = this.owner.lookup('service:router');
this.transitionStub = sinon.stub(this.router, 'transitionTo');
const store = this.owner.lookup('service:store');
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 24) => {
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 48) => {
store.pushPayload('clients/config', {
modelName: 'clients/config',
id: 'foo',
@@ -26,7 +26,7 @@ module('Integration | Component | client count config', function (hooks) {
enabled,
reporting_enabled,
minimum_retention_months,
retention_months: 24,
retention_months: 49,
},
});
this.model = store.peekRecord('clients/config', 'foo');
@@ -46,18 +46,18 @@ module('Integration | Component | client count config', function (hooks) {
'Enabled value matches model'
);
assert.ok(
find('[data-test-row-value="Retention period"]').textContent.includes('24'),
find('[data-test-row-value="Retention period"]').textContent.includes('49'),
'Retention period value matches model'
);
});
test('it should function in edit mode when reporting is disabled', async function (assert) {
assert.expect(12);
assert.expect(13);
const retentionMonths = 60;
this.server.put('/sys/internal/counters/config', (schema, req) => {
const { enabled, retention_months } = JSON.parse(req.requestBody);
const expected = { enabled: 'enable', retention_months: 24 };
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
const expected = { enabled: 'enable', retention_months: retentionMonths };
assert.deepEqual({ enabled, retention_months }, expected, 'Correct data sent in PUT request (1)');
return {};
});
@@ -71,19 +71,27 @@ module('Integration | Component | client count config', function (hooks) {
assert
.dom('label[for="enabled"]')
.hasText('Data collection is off', 'Correct label renders when data collection is off');
assert.dom('[data-test-input="retentionMonths"]').hasValue('24', 'Retention months render');
assert.dom('[data-test-input="retentionMonths"]').hasValue('49', 'Retention months render');
await click('[data-test-input="enabled"]');
await fillIn('[data-test-input="retentionMonths"]', -3);
await fillIn('[data-test-input="retentionMonths"]', 20);
await click('[data-test-clients-config-save]');
assert
.dom('[data-test-inline-error-message]')
.hasText(
'Retention period must be greater than or equal to 24.',
'Validation error shows for incorrect retention period'
'Retention period must be greater than or equal to 48.',
'Validation error shows for min retention period'
);
await fillIn('[data-test-input="retentionMonths"]', 90);
await click('[data-test-clients-config-save]');
assert
.dom('[data-test-inline-error-message]')
.hasText(
'Retention period must be less than or equal to 60.',
'Validation error shows for max retention period'
);
await fillIn('[data-test-input="retentionMonths"]', 24);
await fillIn('[data-test-input="retentionMonths"]', retentionMonths);
await click('[data-test-clients-config-save]');
assert
.dom('[data-test-clients-config-modal="title"]')
@@ -114,7 +122,7 @@ module('Integration | Component | client count config', function (hooks) {
this.server.put('/sys/internal/counters/config', (schema, req) => {
const { enabled, retention_months } = JSON.parse(req.requestBody);
const expected = { enabled: 'enable', retention_months: 48 };
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
assert.deepEqual({ enabled, retention_months }, expected, 'Correct data sent in PUT request (2)');
return {};
});
@@ -125,7 +133,7 @@ module('Integration | Component | client count config', function (hooks) {
`);
assert.dom('[data-test-input="enabled"]').doesNotExist('Data collection input not shown ');
assert.dom('[data-test-input="retentionMonths"]').hasValue('24', 'Retention months render');
assert.dom('[data-test-input="retentionMonths"]').hasValue('49', 'Retention months render');
await fillIn('[data-test-input="retentionMonths"]', 5);
await click('[data-test-clients-config-save]');
@@ -145,8 +153,8 @@ module('Integration | Component | client count config', function (hooks) {
this.server.put('/sys/internal/counters/config', (schema, req) => {
const { enabled, retention_months } = JSON.parse(req.requestBody);
const expected = { enabled: 'enable', retention_months: 24 };
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
const expected = { enabled: 'enable', retention_months: 48 };
assert.deepEqual({ enabled, retention_months }, expected, 'Correct data sent in PUT request (3)');
return {};
});
@@ -155,7 +163,7 @@ module('Integration | Component | client count config', function (hooks) {
await render(hbs`
<Clients::Config @model={{this.model}} @mode="edit" />
`);
await fillIn('[data-test-input="retentionMonths"]', 24);
await fillIn('[data-test-input="retentionMonths"]', 48);
await click('[data-test-clients-config-save]');
});
});

View File

@@ -59,23 +59,23 @@ module('Integration | Util | client count utils', function (hooks) {
const expected = [
{
previousVersion: '1.9.0',
timestampInstalled: '2023-08-02T00:00:00.000Z',
timestampInstalled: '2023-08-02T00:00:00Z',
version: '1.9.1',
},
{
previousVersion: '1.9.1',
timestampInstalled: '2023-09-02T00:00:00.000Z',
timestampInstalled: '2023-09-02T00:00:00Z',
version: '1.10.1',
},
{
previousVersion: '1.16.0',
timestampInstalled: '2023-12-02T00:00:00.000Z',
timestampInstalled: '2023-12-02T00:00:00Z',
version: '1.17.0',
},
];
// set start/end times longer than version history to test all relevant upgrades return
const startTime = '2023-06-02T00:00:00Z'; // first upgrade installed '2023-07-02T00:00:00Z'
const endTime = '2024-03-04T16:14:21.000Z'; // latest upgrade installed '2023-12-02T01:00:00.000Z'
const endTime = '2024-03-04T16:14:21Z'; // latest upgrade installed '2023-12-02T00:00:00Z'
const filteredHistory = filterVersionHistory(this.versionHistory, startTime, endTime);
assert.deepEqual(
JSON.stringify(filteredHistory),
@@ -99,17 +99,17 @@ module('Integration | Util | client count utils', function (hooks) {
const expected = [
{
previousVersion: '1.9.0',
timestampInstalled: '2023-08-02T00:00:00.000Z',
timestampInstalled: '2023-08-02T00:00:00Z',
version: '1.9.1',
},
{
previousVersion: '1.9.1',
timestampInstalled: '2023-09-02T00:00:00.000Z',
timestampInstalled: '2023-09-02T00:00:00Z',
version: '1.10.1',
},
];
const startTime = '2023-08-02T00:00:00.000Z'; // same date as 1.9.1 install date to catch same day edge cases
const endTime = '2023-11-02T00:00:00.000Z';
const startTime = '2023-08-02T00:00:00Z'; // same date as 1.9.1 install date to catch same day edge cases
const endTime = '2023-11-02T00:00:00Z';
const filteredHistory = filterVersionHistory(this.versionHistory, startTime, endTime);
assert.deepEqual(
JSON.stringify(filteredHistory),
@@ -121,7 +121,7 @@ module('Integration | Util | client count utils', function (hooks) {
{
version: '1.10.3',
previousVersion: '1.10.1',
timestampInstalled: '2023-09-23T00:00:00.000Z',
timestampInstalled: '2023-09-23T00:00:00Z',
},
'it does not return subsequent patch versions of the same notable upgrade version'
);