Skip to content

Commit 3fa02b1

Browse files
committed
pretender starter files
1 parent 6c13863 commit 3fa02b1

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

starter-files/015-pretender-server.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
*
3+
* @param {any} body
4+
* @returns {ResponseHandler}
5+
*/
6+
function jsonResponse(body) {
7+
return function() {
8+
return [200, {}, JSON.stringify(body)];
9+
};
10+
}
11+
12+
/**
13+
* @this {Pretender}
14+
*/
15+
function setupServer() {
16+
this.get(
17+
'/api/users',
18+
jsonResponse([
19+
{ id: 1, name: 'Sample McFixture' },
20+
{ id: 2, name: 'Testy Assertington' },
21+
])
22+
);
23+
this.get(
24+
'/api/teams',
25+
jsonResponse([
26+
{
27+
id: 'gh',
28+
name: 'GitHub',
29+
},
30+
])
31+
);
32+
this.get(
33+
'/api/teams/gh',
34+
jsonResponse({
35+
id: 'gh',
36+
name: 'GitHub',
37+
channels: [
38+
{
39+
id: 'prs',
40+
name: 'Pull Requests',
41+
},
42+
],
43+
})
44+
);
45+
this.get(
46+
'/api/teams/gh/channels/prs',
47+
jsonResponse({
48+
id: 'prs',
49+
name: 'Pull Requests',
50+
})
51+
);
52+
}

starter-files/016-pretender-server.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
*
3+
* @param {any} body
4+
* @returns {ResponseHandler}
5+
*/
6+
function jsonResponse(body) {
7+
return function() {
8+
return [200, {}, JSON.stringify(body)];
9+
};
10+
}
11+
12+
/**
13+
* @this {Pretender}
14+
*/
15+
function setupServer() {
16+
this.get(
17+
'/api/teams/gh/channels/prs',
18+
jsonResponse({
19+
id: 'prs',
20+
teamId: 'gh',
21+
name: 'Pull Requests',
22+
})
23+
);
24+
this.get(
25+
'/api/teams/gh/channels/prs/messages',
26+
jsonResponse([
27+
{
28+
id: 1,
29+
user: {
30+
name: 'Testy Testerson',
31+
},
32+
body: 'Hello Tests',
33+
},
34+
])
35+
);
36+
}

0 commit comments

Comments
 (0)