From 1af67dc5967d072a1bd30459595ec6b0f279b65f Mon Sep 17 00:00:00 2001 From: Arthur Deierlein Date: Mon, 30 Oct 2023 10:23:17 +0100 Subject: [PATCH] chore(ember/mirage): added maintainers and users --- ember/mirage/config.js | 2 ++ ember/mirage/factories/maintainer.js | 7 +++++++ ember/mirage/factories/project.js | 17 +++++++++++++++++ ember/mirage/factories/user.js | 8 ++++++-- ember/mirage/scenarios/default.js | 2 ++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 ember/mirage/factories/maintainer.js diff --git a/ember/mirage/config.js b/ember/mirage/config.js index 88d428dc..6589dbc0 100644 --- a/ember/mirage/config.js +++ b/ember/mirage/config.js @@ -40,6 +40,8 @@ function routes() { this.passthrough('https://outdated.local/auth/**'); this.namespace = '/api'; + this.resource('maintainers'); + this.resource('users'); this.resource('projects'); this.resource('versions'); this.resource('release-versions'); diff --git a/ember/mirage/factories/maintainer.js b/ember/mirage/factories/maintainer.js new file mode 100644 index 00000000..f3672709 --- /dev/null +++ b/ember/mirage/factories/maintainer.js @@ -0,0 +1,7 @@ +import { Factory, belongsTo } from 'miragejs'; + +export default Factory.extend({ + project: belongsTo(), + user: belongsTo(), + isPrimary: (index) => index === 0, +}); diff --git a/ember/mirage/factories/project.js b/ember/mirage/factories/project.js index 0d5e4fe6..ecdbdbd5 100644 --- a/ember/mirage/factories/project.js +++ b/ember/mirage/factories/project.js @@ -24,4 +24,21 @@ export default Factory.extend({ }); }, }), + withMaintainers: trait({ + afterCreate(project, server) { + project.update({ + maintainers: [ + server.create('maintainer', { + user: server.create('user'), + project, + isPrimary: true, + }), + server.create('maintainer', { + user: server.create('user'), + project, + }), + ], + }); + }, + }), }); diff --git a/ember/mirage/factories/user.js b/ember/mirage/factories/user.js index 54a1b384..31032629 100644 --- a/ember/mirage/factories/user.js +++ b/ember/mirage/factories/user.js @@ -5,6 +5,10 @@ export default Factory.extend({ idpId: () => faker.string.uuid, firstName: () => faker.person.firstName(), lastName: () => faker.person.lastName(), - email: () => faker.internet.email(), - username: () => faker.internet.userName(), + email() { + return `${this.firstName}.${this.lastName}@example.com`.toLowerCase(); + }, + username() { + return `${this.firstName}${this.lastName[0]}`.toLowerCase(); + }, }); diff --git a/ember/mirage/scenarios/default.js b/ember/mirage/scenarios/default.js index f3aa2859..801cdfca 100644 --- a/ember/mirage/scenarios/default.js +++ b/ember/mirage/scenarios/default.js @@ -6,4 +6,6 @@ export default function (server) { // server.createList('post', 10); server.createList('project', 3, 'withVersions'); server.createList('project', 1); + server.createList('project', 2, 'withMaintainers', 'withVersions'); + server.createList('user', 2); }