Skip to content

Commit 1dffc8a

Browse files
committed
msw: Import existing fixtures
1 parent abfa49d commit 1dffc8a

File tree

11 files changed

+1022
-0
lines changed

11 files changed

+1022
-0
lines changed

packages/crates-io-msw/fixtures.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import CATEGORIES from './fixtures/categories.js';
2+
import CRATE_OWNERSHIPS from './fixtures/crate-ownerships.js';
3+
import CRATES from './fixtures/crates.js';
4+
import DEPENDENCIES from './fixtures/dependencies.js';
5+
import KEYWORDS from './fixtures/keywords.js';
6+
import TEAMS from './fixtures/teams.js';
7+
import USERS from './fixtures/users.js';
8+
import VERSION_DOWNLOADS from './fixtures/version-downloads.js';
9+
import VERSIONS from './fixtures/versions.js';
10+
import { db } from './index.js';
11+
12+
export function loadFixtures() {
13+
CATEGORIES.forEach(it => db.category.create(it));
14+
let keywords = KEYWORDS.map(it => db.keyword.create(it));
15+
16+
let users = USERS.map(it => db.user.create(it));
17+
let teams = TEAMS.map(it => db.team.create(it));
18+
19+
let crates = CRATES.map(it => {
20+
if (it.keywordIds) {
21+
it.keywords = it.keywordIds.map(id => keywords.find(k => k.id === id)).filter(Boolean);
22+
delete it.keywordIds;
23+
}
24+
25+
return db.crate.create(it);
26+
});
27+
28+
CRATE_OWNERSHIPS.forEach(it => {
29+
if (it.crateId) {
30+
it.crate = crates.find(c => c.name === it.crateId);
31+
delete it.crateId;
32+
}
33+
if (it.teamId) {
34+
it.team = teams.find(t => t.id === it.teamId);
35+
delete it.teamId;
36+
}
37+
if (it.userId) {
38+
it.user = users.find(u => u.id === it.userId);
39+
delete it.userId;
40+
}
41+
42+
return db.crateOwnership.create(it);
43+
});
44+
45+
let versions = VERSIONS.map(it => {
46+
if (it.crateId) {
47+
it.crate = crates.find(c => c.name === it.crateId);
48+
delete it.crateId;
49+
}
50+
51+
return db.version.create(it);
52+
});
53+
54+
DEPENDENCIES.forEach(it => {
55+
if (it.crateId) {
56+
it.crate = crates.find(c => c.name === it.crateId);
57+
delete it.crateId;
58+
}
59+
if (it.versionId) {
60+
it.version = versions.find(v => v.id === it.versionId);
61+
delete it.versionId;
62+
}
63+
64+
return db.dependency.create(it);
65+
});
66+
67+
VERSION_DOWNLOADS.forEach(it => {
68+
if (it.versionId) {
69+
it.version = versions.find(v => v.id === it.versionId);
70+
delete it.versionId;
71+
}
72+
73+
return db.versionDownload.create(it);
74+
});
75+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'vitest';
2+
3+
import { loadFixtures } from './fixtures.js';
4+
5+
test('loadFixtures() succeeds', async function () {
6+
loadFixtures();
7+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export default [
2+
{
3+
category: 'API bindings',
4+
created_at: '2017-01-20T14:51:49Z',
5+
description:
6+
'Idiomatic wrappers of specific APIs for convenient access from Rust. Includes HTTP API wrappers as well. Non-idiomatic or unsafe bindings can be found in External FFI bindings.',
7+
id: 'api-bindings',
8+
slug: 'api-bindings',
9+
},
10+
{
11+
category: 'Algorithms',
12+
created_at: '2017-01-20T14:51:49Z',
13+
description: 'Rust implementations of core algorithms such as hashing, sorting, searching, and more.',
14+
id: 'algorithms',
15+
slug: 'algorithms',
16+
},
17+
{
18+
category: 'Asynchronous',
19+
created_at: '2017-01-20T14:51:49Z',
20+
description:
21+
'Crates to help you deal with events independently of the main program flow, using techniques like futures, promises, waiting, or eventing.',
22+
id: 'asynchronous',
23+
slug: 'asynchronous',
24+
},
25+
];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default [
2+
{
3+
crateId: 'nanomsg',
4+
teamId: 1,
5+
},
6+
{
7+
crateId: 'nanomsg',
8+
teamId: 303,
9+
},
10+
{
11+
crateId: 'nanomsg',
12+
userId: 2,
13+
},
14+
{
15+
crateId: 'nanomsg',
16+
userId: 303,
17+
},
18+
];

0 commit comments

Comments
 (0)