Skip to content

Commit 1facbe2

Browse files
committed
a PUT test
1 parent c800042 commit 1facbe2

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

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

+33-15
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ testEnvironment.deploy()
1616
.then(_ => test.onFinish(testEnvironment.undeploy))
1717
.catch(console.error);
1818

19-
// PUT a fruit
20-
21-
// DELETE a fruit
22-
2319
function runTests (route) {
2420
// GET fruits
2521
test('/api/fruits', t => {
@@ -89,15 +85,37 @@ function runTests (route) {
8985
});
9086
});
9187

92-
// test('/api/greeting with query param', t => {
93-
// t.plan(1);
94-
// supertest(route)
95-
// .get('/api/greeting?name=luke')
96-
// .expect(200)
97-
// .expect('Content-Type', /json/)
98-
// .then(response => {
99-
// t.equal(response.body.content, 'Hello, luke', 'should return the Hello, luke Greeting');
100-
// t.end();
101-
// });
102-
// });
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+
});
103121
}

0 commit comments

Comments
 (0)