Skip to content

Commit a1cbae0

Browse files
committed
chore(integration-test): adding integration tests using the rhoaster module
1 parent 59b84ea commit a1cbae0

File tree

4 files changed

+150
-2
lines changed

4 files changed

+150
-2
lines changed

Diff for: .travis.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@ dist: trusty
33
language: node_js
44
node_js:
55
- "8"
6-
- "7"
76

87
before_install:
98
- npm install -g npm@5
109
- npm install -g greenkeeper-lockfile@1
11-
before_script: greenkeeper-lockfile-update
10+
before_script:
11+
- greenkeeper-lockfile-update
12+
- sudo mount --make-shared /
13+
- sudo service docker stop
14+
- sudo sed -i 's/DOCKER_OPTS=\"/DOCKER_OPTS=\"--insecure-registry 172.30.0.0\/16 /' /etc/default/docker
15+
- sudo service docker start
16+
- wget https://github.com/openshift/origin/releases/download/v3.9.0-alpha.3/openshift-origin-client-tools-v3.9.0-alpha.3-78ddc10-linux-64bit.tar.gz
17+
- tar xvzOf openshift-origin-client-tools-v3.9.0-alpha.3-78ddc10-linux-64bit.tar.gz > oc.bin
18+
- sudo mv oc.bin /usr/bin/oc
19+
- sudo chmod 755 /usr/bin/oc
1220
script:
1321
- npm run ci
22+
- oc cluster up
23+
- sleep 10
24+
- oc new-app -e POSTGRESQL_USER=luke -ePOSTGRESQL_PASSWORD=secret -ePOSTGRESQL_DATABASE=my_data openshift/postgresql-92-centos7 --name=my-database
25+
- sleep 10
26+
- npm run test:integration
1427
# Only the node version 8 job will upload the lockfile
1528
after_script: greenkeeper-lockfile-upload
1629
branches:

Diff for: package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"license": "Apache-2.0",
77
"scripts": {
88
"test": "tape test/*.js | tap-spec",
9+
"test:integration": "tape test/integration/*.js | tap-spec",
10+
"test:integration:undeploy": "nodeshift --strictSSL=false undeploy",
911
"lint": "eslint test/*.js app.js bin/*",
1012
"prepare": "echo 'To confirm CVE compliance, run \"npm run security-check\"' ",
1113
"security-check": "nsp check",
@@ -56,6 +58,7 @@
5658
"nsp": "~3.2.1",
5759
"nyc": "~11.6.0",
5860
"proxyquire": "^2.0.0",
61+
"rhoaster": "~0.2.0",
5962
"standard-version": "^4.3.0",
6063
"supertest": "^3.0.0",
6164
"szero": "^1.0.0",

Diff for: test/integration/fruits-integration-test.js

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
'use strict';
2+
3+
'use strict';
4+
5+
const test = require('tape');
6+
const supertest = require('supertest');
7+
const rhoaster = require('rhoaster');
8+
9+
const testEnvironment = rhoaster({
10+
deploymentName: 'nodejs-rest-http-crud',
11+
nodeVersion: '8.x'
12+
});
13+
14+
testEnvironment.deploy()
15+
.then(runTests)
16+
.then(_ => test.onFinish(testEnvironment.undeploy))
17+
.catch(console.error);
18+
19+
function runTests (route) {
20+
// GET fruits
21+
test('/api/fruits', t => {
22+
t.plan(2);
23+
supertest(route)
24+
.get('/api/fruits')
25+
.expect(200)
26+
.expect('Content-Type', /json/)
27+
.then(response => {
28+
t.equal(Array.isArray(response.body), true, 'response is an Array');
29+
t.equal(response.body.length, 3, 'should be initialized with 3 items');
30+
t.end();
31+
});
32+
});
33+
34+
// GET 1 fruit
35+
test('/api/fruit/:id', t => {
36+
t.plan(4);
37+
supertest(route)
38+
.get('/api/fruits/1')
39+
.expect(200)
40+
.expect('Content-Type', /json/)
41+
.then(response => {
42+
t.equal(Array.isArray(response.body), false, 'not an array returned');
43+
t.equal(response.body.id, 1, 'id is 1');
44+
t.equal(response.body.name, 'Apple', 'name is Apple');
45+
t.equal(response.body.stock, '10', 'stock is 10');
46+
t.end();
47+
});
48+
});
49+
50+
// GET 1 fruit that doesn't exist
51+
test('/api/fruit/:id - does not exist', t => {
52+
t.plan(1);
53+
supertest(route)
54+
.get('/api/fruits/10')
55+
.expect(404)
56+
.expect('Content-Type', /text/)
57+
.then(response => {
58+
t.equal(response.text, 'Item 10 not found', 'return not found string');
59+
t.end();
60+
});
61+
});
62+
63+
// POST a fruit
64+
test('POST /api/fruit/', t => {
65+
t.plan(4);
66+
const fruitData = {
67+
name: 'Banana',
68+
stock: '10'
69+
};
70+
71+
supertest(route)
72+
.post('/api/fruits')
73+
.send(fruitData)
74+
.expect(201)
75+
.expect('Content-Type', /json/)
76+
.then(response => {
77+
t.equal(Array.isArray(response.body), false, 'not an array returned');
78+
t.ok(response.body.id, 'has a new id field');
79+
t.equal(response.body.name, fruitData.name, `name is ${fruitData.name}`);
80+
t.equal(response.body.stock, fruitData.stock, `stock is ${fruitData.stock}`);
81+
82+
// clean up
83+
supertest(route).delete(`/api/fruits/${response.body.id}`).then(_ => ({}));
84+
t.end();
85+
});
86+
});
87+
88+
// PUT a fruit
89+
test('PUT /api/fruit/:id', t => {
90+
// t.plan(0);
91+
const fruitData = {
92+
name: 'put fruit',
93+
stock: '10'
94+
};
95+
96+
// First create the new fruit
97+
supertest(route)
98+
.post('/api/fruits')
99+
.send(fruitData)
100+
.expect(201)
101+
.then(response => {
102+
const id = response.body.id;
103+
104+
const updatedFruit = {
105+
name: response.body.name,
106+
stock: '20'
107+
};
108+
109+
supertest(route)
110+
.put(`/api/fruits/${id}`)
111+
.send(updatedFruit)
112+
.expect(204)
113+
.then(putResponse => {
114+
// clean up
115+
t.pass('should return with an empty response');
116+
supertest(route).delete(`/api/fruits/${response.body.id}`).then(_ => ({}));
117+
t.end();
118+
});
119+
});
120+
});
121+
}

0 commit comments

Comments
 (0)