Icu 8073 mirage recording connection channel (#109)
* feat: 🎸 Add mirage data for recordings, connections, channels ✅ Closes: ICU-8073
This commit is contained in:
1 parent
7af4625457
commit
ce83346461
25 files changed
+384
-2
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
|
||||
|
||||
export default class ConnectionSerializer extends ApplicationSerializer.extend(
|
||||
EmbeddedRecordsMixin
|
||||
) {
|
||||
attrs = {
|
||||
channels: { embedded: 'always' },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
|
||||
export default class RecordingSerializer extends ApplicationSerializer.extend(
|
||||
EmbeddedRecordsMixin
|
||||
) {
|
||||
attrs = {
|
||||
connections: { embedded: 'always' },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/serializers/connection';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/serializers/recording';
|
||||
@@ -680,6 +680,15 @@ function routes() {
|
||||
}
|
||||
);
|
||||
|
||||
// session recordings
|
||||
this.get(
|
||||
'/recordings',
|
||||
({ recordings }, { queryParams: { scope_id: scopeId } }) => {
|
||||
return recordings.where({ scopeId });
|
||||
}
|
||||
);
|
||||
this.get('/recordings/:id');
|
||||
|
||||
/* Uncomment the following line and the Response import above
|
||||
* Then change the response code to simulate error responses.
|
||||
* this.get('/scopes', () => new Response(505));
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import factory from '../generated/factories/channel';
|
||||
import generateId from '../helpers/id';
|
||||
import { TYPES_CHANNEL as types } from 'api/models/channel';
|
||||
|
||||
export default factory.extend({
|
||||
id: () => generateId('srcc_'),
|
||||
type: (i) => types[i % types.length],
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import factory from '../generated/factories/connection';
|
||||
import generateId from '../helpers/id';
|
||||
|
||||
export default factory.extend({
|
||||
id: () => generateId('src_'),
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import factory from '../generated/factories/recording';
|
||||
import permissions from '../helpers/permissions';
|
||||
import generateId from '../helpers/id';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { trait } from 'miragejs';
|
||||
import { TYPES_RECORDING as types } from 'api/models/recording';
|
||||
|
||||
const pickRandomElement = (arr) => faker.helpers.arrayElement(arr);
|
||||
export default factory.extend({
|
||||
id: () => generateId('sr_'),
|
||||
|
||||
// Cycle through available types
|
||||
type: (i) => types[i % types.length],
|
||||
|
||||
authorized_actions: () =>
|
||||
permissions.authorizedActionsFor('recording') || ['no-op', 'read', 'list'],
|
||||
|
||||
withNonExistingUserAndTarget: trait({
|
||||
afterCreate(recording, server) {
|
||||
const user = pickRandomElement(server.schema.users.all().models);
|
||||
user.id = 'deleted_user';
|
||||
const session = pickRandomElement(server.schema.sessions.all().models);
|
||||
session.id = 'deleted_session';
|
||||
const target = session.target;
|
||||
target.id = 'deleted_target';
|
||||
|
||||
recording.update({
|
||||
user,
|
||||
target,
|
||||
session,
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
withExistingUserAndTarget: trait({
|
||||
afterCreate(recording, server) {
|
||||
const user = pickRandomElement(server.schema.users.all().models);
|
||||
const session = pickRandomElement(server.schema.sessions.all().models);
|
||||
const target = session.target;
|
||||
|
||||
recording.update({
|
||||
user,
|
||||
target,
|
||||
session,
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
withConnectionAndChannels: trait({
|
||||
afterCreate(recording, server) {
|
||||
server
|
||||
.createList('connection', 3, { recording })
|
||||
.forEach((connection) => {
|
||||
server.createList('channel', 3, { connection });
|
||||
});
|
||||
},
|
||||
}),
|
||||
});
|
||||
@@ -30,7 +30,6 @@ export default factory.extend({
|
||||
'credential-stores': ['create', 'list'],
|
||||
'auth-methods': ['create', 'list'],
|
||||
'host-catalogs': ['create', 'list'],
|
||||
'storage-buckets': ['create', 'list'],
|
||||
};
|
||||
|
||||
// Worker permissions only available on the global scope
|
||||
@@ -38,6 +37,10 @@ export default factory.extend({
|
||||
collectionActions.workers = ['create:worker-led', 'list'];
|
||||
}
|
||||
|
||||
if (this.type === 'global' || this.type === 'org') {
|
||||
collectionActions['storage-buckets'] = ['create', 'list'];
|
||||
}
|
||||
|
||||
return collectionActions;
|
||||
},
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import factory from '../generated/factories/storage-bucket';
|
||||
import permissions from '../helpers/permissions';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
/**
|
||||
* GeneratedChannelModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
bytes_up: () => faker.datatype.number(),
|
||||
bytes_down: () => faker.datatype.number(),
|
||||
errors: () => faker.datatype.number({ max: 10 }),
|
||||
started_time() {
|
||||
return faker.date.recent(3, this.finished_time);
|
||||
},
|
||||
finished_time: () => faker.date.recent(),
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
/**
|
||||
* GeneratedConnectionModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
bytes_up: () => faker.datatype.number(),
|
||||
bytes_down: () => faker.datatype.number(),
|
||||
errors: () => faker.datatype.number({ max: 10 }),
|
||||
started_time() {
|
||||
return faker.date.recent(3, this.finished_time);
|
||||
},
|
||||
finished_time: () => faker.date.recent(),
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
/**
|
||||
* GeneratedRecordModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
bytes_up: () => faker.datatype.number(),
|
||||
bytes_down: () => faker.datatype.number(),
|
||||
errors: () => faker.datatype.number({ max: 10 }),
|
||||
started_time() {
|
||||
return faker.date.recent(3, this.finished_time);
|
||||
},
|
||||
finished_time() {
|
||||
return faker.date.recent(1, this.updated_time);
|
||||
},
|
||||
updated_time: () => faker.date.recent(),
|
||||
deleted_on: () => faker.date.soon(),
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
@@ -5,7 +10,6 @@ import { faker } from '@faker-js/faker';
|
||||
* GeneratedStorageBucketModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
type: 'plugin',
|
||||
name: () => faker.random.words(),
|
||||
description: () => faker.random.words(),
|
||||
created_time: () => faker.date.recent(),
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { belongsTo, Model } from 'miragejs';
|
||||
|
||||
export default Model.extend({
|
||||
connection: belongsTo(),
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { belongsTo, hasMany, Model } from 'miragejs';
|
||||
|
||||
export default Model.extend({
|
||||
recording: belongsTo(),
|
||||
channels: hasMany(),
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { belongsTo, hasMany, Model } from 'miragejs';
|
||||
|
||||
export default Model.extend({
|
||||
scope: belongsTo(),
|
||||
user: belongsTo(),
|
||||
session: belongsTo(),
|
||||
target: belongsTo(),
|
||||
connections: hasMany(),
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { belongsTo } from 'miragejs';
|
||||
import Model from './base';
|
||||
export default Model.extend({
|
||||
|
||||
@@ -113,4 +113,24 @@ export default function (server) {
|
||||
// Session Recordings and Storage Buckets
|
||||
server.createList('storage-bucket', 3, { scope: globalScope });
|
||||
server.createList('storage-bucket', 2, { scope: orgScope });
|
||||
server.createList(
|
||||
'recording',
|
||||
3,
|
||||
{ scope: globalScope },
|
||||
'withConnectionAndChannels',
|
||||
'withExistingUserAndTarget'
|
||||
);
|
||||
server.create(
|
||||
'recording',
|
||||
{ scope: globalScope },
|
||||
'withConnectionAndChannels',
|
||||
'withNonExistingUserAndTarget'
|
||||
);
|
||||
server.createList(
|
||||
'recording',
|
||||
2,
|
||||
{ scope: orgScope },
|
||||
'withConnectionAndChannels',
|
||||
'withExistingUserAndTarget'
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'channel',
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import ApplicationSerializer from './application';
|
||||
import ChannelSerializer from './channel';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'connection',
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(
|
||||
this,
|
||||
arguments
|
||||
);
|
||||
const { channels } = this.schema;
|
||||
if (model.channelIds) {
|
||||
json.channels = model.channelIds.map((id) => {
|
||||
const channel = channels.find(id);
|
||||
return ChannelSerializer.prototype._hashForModel.apply(this, [channel]);
|
||||
});
|
||||
}
|
||||
return json;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import ApplicationSerializer from './application';
|
||||
import ConnectionSerializer from './connection';
|
||||
import UserSerializer from './user';
|
||||
import TargetSerializer from './target';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'recording',
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(
|
||||
this,
|
||||
arguments
|
||||
);
|
||||
const { connections, users, targets } = this.schema;
|
||||
|
||||
// Manually map our models to the actual embedded json representation
|
||||
if (model.connectionIds) {
|
||||
json.connections = model.connectionIds.map((id) => {
|
||||
const connection = connections.find(id);
|
||||
return ConnectionSerializer.prototype._hashForModel.apply(this, [
|
||||
connection,
|
||||
]);
|
||||
});
|
||||
}
|
||||
if (model.userId) {
|
||||
const user = users.find(model.userId);
|
||||
json.user = UserSerializer.prototype._hashForModel.apply(this, [user]);
|
||||
}
|
||||
if (model.targetId) {
|
||||
const target = targets.find(model.targetId);
|
||||
json.target = TargetSerializer.prototype._hashForModel.apply(this, [
|
||||
target,
|
||||
]);
|
||||
}
|
||||
|
||||
json.session_id = model.sessionId;
|
||||
return json;
|
||||
},
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import ApplicationSerializer from './application';
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'storage-bucket',
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Serializer | connection', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let serializer = store.serializerFor('connection');
|
||||
|
||||
assert.ok(serializer);
|
||||
});
|
||||
|
||||
test('it serializes records', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let record = store.createRecord('connection', {});
|
||||
|
||||
let serializedRecord = record.serialize();
|
||||
|
||||
assert.ok(serializedRecord);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Serializer | recording', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let serializer = store.serializerFor('recording');
|
||||
|
||||
assert.ok(serializer);
|
||||
});
|
||||
|
||||
test('it serializes records', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let record = store.createRecord('recording', {});
|
||||
|
||||
let serializedRecord = record.serialize();
|
||||
|
||||
assert.ok(serializedRecord);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user