UNPKG

3.66 kBJavaScriptView Raw
1/*
2 Here we simulate the response of the server when asked
3 to get a list of branches from the privproject1 repo
4
5 nock will simulate a gitlab server running at
6 localhost:80, where Strider Tester, a user is
7 registered with the name "stridertester", and
8 has been registered with api token - zRtVsmeznn7ySatTrnrp
9 stridertester is an "owner" of a group named "testunion"
10 and has admin access to three projects -
11 testunion / unionproject1
12 Strider Tester / pubproject1
13 Strider Tester / privproject1
14
15 privproject has two branches firstbranch and master
16 */
17
18var nock = require('nock');
19
20module.exports = function () {
21
22 //--------------------------------------------------------------------------------------
23 //Simulate a good response that sends the correct branches
24 nock('http://localhost:80')
25 .get('/api/v3/projects/5/repository/branches')
26 .query({"private_token": "zRtVsmeznn7ySatTrnrp", "per_page": "100"})
27 .reply(200, ["1f8b0800000000000003bd914f4f023110c5bf0ae95520fdb74bdb9346397a516e48c8b49d42137631dd723084ef6e1102c68872d1ebbc99f732ef37dd92161a24868498ba6c13b46e49fac4ad9b266662b624fa22faa0400826a5422aaa5a680ca09c730a3c30e625b35450a145b96cb0eb60b177bc5f42bb40df7b1adf3d3c8e878d7f698bfe0a09db3c8fbe23664a24ad9d05ad99b3b606ea18adb50e0e2d528e4e0b1194ac2b2fc9ac4f609397eb847eee21effd3965d580aa01e71356994a19560d29a537541b4a4bd2617f7efcef39a7e831f526d8654c67191b88abe2d61df4fc21df2ef6d36169e1d445be3ef8505eb1b9987ddef82d7e571a4beb8caee4131360d5e1ae7f82d6c0f1992fbcaeaef5332ff0bed0b2b185f4d60b7185dff01a8112bc70d1b5171c582d1843096847ca8f2cd5238bdc0685f8132fa6275c18ce8c90ffcbeb52f0dff1ca6983bbd93b8b937b0e65030000"], {
28 server: 'nginx',
29 date: 'Sat, 22 Aug 2015 07:32:10 GMT',
30 'content-type': 'application/json',
31 'transfer-encoding': 'chunked',
32 connection: 'close',
33 status: '200 OK',
34 etag: 'W/"a5766ebd98e6dcefebb0256942be9cf1"',
35 'cache-control': 'max-age=0, private, must-revalidate',
36 'x-request-id': '6166a894-b650-4e17-9057-6c23bc4e959f',
37 'x-runtime': '0.019611',
38 'content-encoding': 'gzip'
39 });
40
41 //--------------------------------------------------------------------------------------
42 //Simulate a 401 when bad credentials are sent
43 nock('http://localhost:80')
44 .get('/api/v3/projects/5/repository/branches')
45 .query({"private_token": "badkey", "per_page": "100"})
46 .reply(401, {"message": "401 Unauthorized"}, {
47 server: 'nginx',
48 date: 'Sat, 22 Aug 2015 07:45:55 GMT',
49 'content-type': 'application/json',
50 'content-length': '30',
51 connection: 'close',
52 status: '401 Unauthorized',
53 'cache-control': 'no-cache',
54 'x-request-id': 'c487af2c-3a4f-45ff-938e-9ee196429b65',
55 'x-runtime': '0.003879'
56 });
57
58 //--------------------------------------------------------------------------------------
59 //Simulate a 404 when an invalid repo id of "invalidrepo" is sent
60 //Heaven forbid that there actually is a project with repo ID "NaN"
61 nock('http://localhost:80')
62 .get('/api/v3/projects/NaN/repository/branches')
63 .query({"private_token": "zRtVsmeznn7ySatTrnrp", "per_page": "100"})
64 .reply(404, ["1f8b0800000000000003ab56ca4d2d2e4e4c4f55b252323130510828cacf4a4d2e51f0cb2f5170cb2fcd4b51aa050037095a2823000000"], {
65 server: 'nginx',
66 date: 'Sat, 22 Aug 2015 07:56:44 GMT',
67 'content-type': 'application/json',
68 'transfer-encoding': 'chunked',
69 connection: 'close',
70 status: '404 Not Found',
71 'cache-control': 'no-cache',
72 'x-request-id': '60c9a1ef-0dbf-4533-8f6e-0aded176d319',
73 'x-runtime': '0.006694',
74 'content-encoding': 'gzip'
75 });
76};