Skip to content

Commit 663908f

Browse files
committed
mirage: Add "crate" and "version" factories
1 parent 5aa2d66 commit 663908f

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

mirage/factories/crate.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Factory, trait, faker } from 'ember-cli-mirage';
2+
3+
export default Factory.extend({
4+
id(i) {
5+
return `crate-${i}`;
6+
},
7+
8+
name() {
9+
return this.id;
10+
},
11+
12+
description: () => faker.lorem.sentence(),
13+
downloads: () => faker.random.number({ max: 10000 }),
14+
documentation: () => faker.internet.url(),
15+
homepage: () => faker.internet.url(),
16+
repository: () => faker.internet.url(),
17+
license: () => faker.hacker.abbreviation(),
18+
max_version: () => faker.system.semver(),
19+
20+
created_at: () => faker.date.past(),
21+
updated_at() {
22+
return faker.date.between(this.created_at, new Date());
23+
},
24+
25+
badges: () => [],
26+
categories: () => [],
27+
keywords: () => [],
28+
versions: () => [],
29+
_extra_downloads: () => [],
30+
_owner_teams: () => [],
31+
_owner_users: () => [],
32+
33+
links() {
34+
return {
35+
'owner_user': `/api/v1/crates/${this.id}/owner_user`,
36+
'owner_team': `/api/v1/crates/${this.id}/owner_team`,
37+
'reverse_dependencies': `/api/v1/crates/${this.id}/reverse_dependencies`,
38+
'version_downloads': `/api/v1/crates/${this.id}/downloads`,
39+
'versions': `/api/v1/crates/${this.id}/versions`,
40+
};
41+
},
42+
43+
withVersion: trait({
44+
afterCreate(crate, server) {
45+
server.create('version', { crate: crate.id });
46+
}
47+
}),
48+
});

mirage/factories/version.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Factory, faker } from 'ember-cli-mirage';
2+
3+
export default Factory.extend({
4+
id: i => i,
5+
6+
// crate: '...',
7+
8+
num: () => faker.system.semver(),
9+
10+
created_at: () => faker.date.past(),
11+
updated_at() {
12+
return faker.date.between(this.created_at, new Date());
13+
},
14+
15+
yanked: false,
16+
17+
dl_path() {
18+
return `/api/v1/crates/${this.crate}/${this.num}/download`;
19+
},
20+
21+
downloads: () => faker.random.number({ max: 10000 }),
22+
features: () => {},
23+
_authors: () => [],
24+
25+
links() {
26+
return {
27+
'authors': `/api/v1/crates/${this.crate}/${this.num}/authors`,
28+
'dependencies': `/api/v1/crates/${this.crate}/${this.num}/dependencies`,
29+
'version_downloads': `/api/v1/crates/${this.crate}/${this.num}/downloads`,
30+
};
31+
},
32+
33+
afterCreate(version, server) {
34+
let crate = server.schema.crates.find(version.crate);
35+
crate.update({ versions: crate.versions.concat(parseInt(version.id, 10)) });
36+
}
37+
});

0 commit comments

Comments
 (0)