2022-05-30 17:10:44 +00:00
|
|
|
import { Factory } from 'ember-cli-mirage';
|
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2022-08-09 17:17:55 +00:00
|
|
|
import { provide, pickOne } from '../utils';
|
2022-07-22 20:05:35 +00:00
|
|
|
|
2022-05-30 17:10:44 +00:00
|
|
|
export default Factory.extend({
|
|
|
|
id: () => faker.random.words(3).split(' ').join('/').toLowerCase(),
|
|
|
|
path() {
|
|
|
|
return this.id;
|
|
|
|
},
|
2022-07-08 14:08:02 +00:00
|
|
|
namespace: null,
|
2022-06-20 16:48:38 +00:00
|
|
|
createdIndex: 100,
|
|
|
|
modifiedIndex: 100,
|
2022-08-03 16:42:50 +00:00
|
|
|
createTime: () => faker.date.past(15) * 1000000,
|
|
|
|
modifyTime: () => faker.date.recent(1) * 1000000,
|
2022-05-30 17:10:44 +00:00
|
|
|
items() {
|
|
|
|
return (
|
|
|
|
this.Items || {
|
|
|
|
[faker.database.column()]: faker.database.collation(),
|
|
|
|
[faker.database.column()]: faker.database.collation(),
|
|
|
|
[faker.database.column()]: faker.database.collation(),
|
|
|
|
[faker.database.column()]: faker.database.collation(),
|
|
|
|
[faker.database.column()]: faker.database.collation(),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2022-07-08 14:08:02 +00:00
|
|
|
|
|
|
|
afterCreate(variable, server) {
|
|
|
|
if (!variable.namespaceId) {
|
2022-08-09 17:17:55 +00:00
|
|
|
const namespace = pickOne(server.db.jobs)?.namespace || 'default';
|
2022-07-08 14:08:02 +00:00
|
|
|
variable.update({
|
|
|
|
namespace,
|
|
|
|
});
|
2022-07-22 20:05:35 +00:00
|
|
|
} else {
|
|
|
|
variable.update({
|
|
|
|
namespace: variable.namespaceId,
|
|
|
|
});
|
2022-07-08 14:08:02 +00:00
|
|
|
}
|
|
|
|
},
|
2022-05-30 17:10:44 +00:00
|
|
|
});
|