Skip to content

mirage: Use relationship system #2137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 16, 2020
Merged
5 changes: 0 additions & 5 deletions mirage/factories/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,5 @@ export default Factory.extend({
updated_at: '2017-02-24T12:34:56Z',

badges: () => [],
categories: () => [],
keywords: () => [],
versions: () => [],
_extra_downloads: () => [],
_owner_teams: () => [],
_owner_users: () => [],
});
12 changes: 9 additions & 3 deletions mirage/factories/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import { Factory } from 'ember-cli-mirage';
const REQS = ['^0.1.0', '^2.1.3', '0.3.7', '~5.2.12'];

export default Factory.extend({
// crate_id,
// version_id,

default_features: i => i % 4 === 3,
features: () => [],
kind: i => (i % 3 === 0 ? 'dev' : 'normal'),
optional: i => i % 4 !== 3,
req: i => REQS[i % REQS.length],
target: null,

afterCreate(self) {
if (!self.crateId) {
throw new Error(`Missing \`crate\` relationship on \`dependency:${self.id}\``);
}
if (!self.versionId) {
throw new Error(`Missing \`version\` relationship on \`dependency:${self.id}\``);
}
},
});
8 changes: 6 additions & 2 deletions mirage/factories/version-download.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Factory } from 'ember-cli-mirage';

export default Factory.extend({
// version

date: '2019-05-21',
downloads: i => (((i * 42) % 13) + 4) * 2345,

afterCreate(self) {
if (!self.versionId) {
throw new Error(`Missing \`version\` relationship on \`version-download:${self.date}\``);
}
},
});
11 changes: 4 additions & 7 deletions mirage/factories/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ export default Factory.extend({
yanked: false,
license: i => LICENSES[i % LICENSES.length],

dl_path() {
return `/api/v1/crates/${this.crate}/${this.num}/download`;
},

downloads: i => (((i + 13) * 42) % 13) * 1234,

features: () => {},
_authors: () => [],

crate_size: i => (((i + 13) * 42) % 13) * 54321,

afterCreate(version, server) {
let crate = server.schema.crates.find(version.crate);
crate.update({ versions: crate.versions.concat(parseInt(version.id, 10)) });
afterCreate(version) {
if (!version.crateId) {
throw new Error(`Missing \`crate\` relationship on \`version:${version.num}\``);
}
},
});
Loading