Files
threshold-ui/addons/api/mirage/factories/storage-bucket.js
T
Zhihe Li ce83346461 Icu 8073 mirage recording connection channel (#109)
* feat: 🎸 Add mirage data for recordings, connections, channels

✅ Closes: ICU-8073
2023-03-10 14:20:58 -05:00

57 lines
1.4 KiB
JavaScript

/**
* 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';
import generateId from '../helpers/id';
import {
TYPES_STORAGE_BUCKET as types,
TYPES_STORAGE_BUCKET_PLUGIN,
TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
} from 'api/models/storage-bucket';
// Represents known plugin types, except "foobar" which models the possibility
// of receiving an _unknown_ type, which the UI must handle gracefully.
const pluginTypes = [...TYPES_STORAGE_BUCKET_PLUGIN, 'foobar'];
export default factory.extend({
id: () => generateId('sb_'),
// Cycle through available types
type: (i) => types[i % types.length],
authorized_actions: () =>
permissions.authorizedActionsFor('storage-bucket') || [
'no-op',
'read',
'update',
'delete',
],
plugin: function (i) {
if (this.type === 'plugin') {
return {
id: `plugin-id-${i}`,
name: pluginTypes[i % pluginTypes.length],
description: faker.random.words(),
};
}
},
attributes() {
switch (this.plugin?.name) {
case TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3:
return {
region: `us-${faker.address.cardinalDirection()}-${faker.datatype.number(
{
max: 9,
}
)}`,
};
}
},
});