chore: 🤖 More updates for models and mirage (#253)

This commit is contained in:
Zhihe Li authored and GitHub committed 2023-05-17 12:01:34 -04:00
1 parent 6e0cc57509
commit ed5416477d
10 files changed
+61 -20

No files matched your search

@@ -77,12 +77,6 @@ export default class GeneratedSessionRecordingModel extends BaseModel {
})
updated_time;
@attr('date', {
description: 'The time that the Session recording will be deleted.',
readOnly: true,
})
delete_on;
@attr({
description: 'The array of mime types that this recording will support.',
readOnly: true,
@@ -94,4 +88,18 @@ export default class GeneratedSessionRecordingModel extends BaseModel {
readOnly: true,
})
duration;
@attr('string', {
description:
'The current state of the session recording. One of "started", "available" and "unknown".',
readOnly: true,
})
state;
@attr('string', {
description:
'Any error seen during the closing of the session recording. Currently only set if state is "unknown".',
readOnly: true,
})
error_details;
}
@@ -8,6 +8,10 @@ export const TYPES_SESSION_RECORDING = Object.freeze([
TYPE_SESSION_RECORDING_SSH,
]);
export const STATE_SESSION_RECORDING_STARTED = 'started';
export const STATE_SESSION_RECORDING_AVAILABLE = 'available';
export const STATE_SESSION_RECORDING_UNKNOWN = 'unknown';
export default class SessionRecordingModel extends GeneratedSessionRecordingModel {
@hasMany('connection-recording', { async: false }) connection_recordings;
@@ -5,8 +5,13 @@
import factory from '../generated/factories/connection-recording';
import generateId from '../helpers/id';
import { faker } from '@faker-js/faker';
export default factory.extend({
id: () => generateId('cr_'),
connection_id: () => generateId('sc_'),
start_time(i) {
return i % 3 === 2 ? null : faker.date.recent(3, this.end_time);
},
end_time: (i) => (i % 3 === 2 ? null : faker.date.recent()),
});
@@ -8,8 +8,18 @@ import permissions from '../helpers/permissions';
import generateId from '../helpers/id';
import { faker } from '@faker-js/faker';
import { trait } from 'miragejs';
import { TYPES_SESSION_RECORDING as types } from 'api/models/session-recording';
import {
TYPES_SESSION_RECORDING as types,
STATE_SESSION_RECORDING_STARTED,
STATE_SESSION_RECORDING_AVAILABLE,
STATE_SESSION_RECORDING_UNKNOWN,
} from 'api/models/session-recording';
const states = [
STATE_SESSION_RECORDING_STARTED,
STATE_SESSION_RECORDING_AVAILABLE,
STATE_SESSION_RECORDING_UNKNOWN,
];
const pickRandomElement = (arr) => faker.helpers.arrayElement(arr);
export default factory.extend({
id: () => generateId('sr_'),
@@ -17,6 +27,15 @@ export default factory.extend({
// Cycle through available types
type: (i) => types[i % types.length],
state: (i) => states[i % states.length],
start_time(i) {
return i % 4 === 3 ? null : faker.date.recent(3, this.end_time);
},
end_time(i) {
return i % 4 === 3 ? null : faker.date.recent(1, this.updated_time);
},
authorized_actions: () =>
permissions.authorizedActionsFor('session-recording') || [
'no-op',
@@ -15,9 +15,5 @@ export default Factory.extend({
bytes_down: () =>
faker.random.numeric(faker.datatype.number({ min: 1, max: 12 })),
errors: () => faker.datatype.number({ max: 10 }),
start_time() {
return faker.date.recent(3, this.end_time);
},
end_time: () => faker.date.recent(),
duration: () => `${faker.datatype.number()}s`,
});
@@ -15,13 +15,6 @@ export default Factory.extend({
bytes_down: () =>
faker.random.numeric(faker.datatype.number({ min: 1, max: 12 })),
errors: () => faker.datatype.number({ max: 10 }),
start_time() {
return faker.date.recent(3, this.end_time);
},
end_time() {
return faker.date.recent(1, this.updated_time);
},
updated_time: () => faker.date.recent(),
deleted_on: () => faker.date.soon(),
duration: () => `${faker.datatype.number()}s`,
});
@@ -11,7 +11,7 @@ import { helper } from '@ember/component/helper';
*/
export default helper(function formatDateIsoHuman(params /*, hash*/) {
return params[0]
.toISOString()
?.toISOString()
.replace('T', ' ')
.replace(/\.\d*Z/, '');
});
+1 -1
View File
@@ -10,5 +10,5 @@ import { helper } from '@ember/component/helper';
* e.g. "2020-01-01T00:00:00.999Z".
*/
export default helper(function formatDateIso(params /*, hash*/) {
return params[0].toISOString();
return params[0]?.toISOString();
});
@@ -18,4 +18,12 @@ module('Integration | Helper | format-date-iso-human', function (hooks) {
assert.strictEqual(this.element.textContent.trim(), '2020-01-01 00:00:00');
});
test('it renders when null', async function (assert) {
this.set('inputValue', null);
await render(hbs`{{format-date-iso-human this.inputValue }}`);
assert.strictEqual(this.element.textContent.trim(), '');
});
});
@@ -21,4 +21,12 @@ module('Integration | Helper | format-date-iso', function (hooks) {
'2020-01-01T00:00:00.999Z'
);
});
test('it renders when null', async function (assert) {
this.set('inputValue', null);
await render(hbs`{{format-date-iso this.inputValue}}`);
assert.strictEqual(this.element.textContent.trim(), '');
});
});