2021-07-12 19:25:37 +02:00
|
|
|
import { Api } from "../fixtures";
|
2020-05-27 19:38:40 +02:00
|
|
|
|
2020-07-02 10:03:00 +02:00
|
|
|
let chai = require("chai/chai");
|
2019-08-13 09:45:10 +02:00
|
|
|
let assert = chai.assert;
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2019-08-13 09:45:10 +02:00
|
|
|
describe("common/api", () => {
|
2021-01-09 04:41:33 +01:00
|
|
|
const getCollectionResponse = [
|
|
|
|
{ id: 1, name: "John Smith" },
|
|
|
|
{ id: 1, name: "John Smith" },
|
|
|
|
];
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
const getEntityResponse = {
|
|
|
|
id: 1,
|
|
|
|
name: "John Smith",
|
|
|
|
};
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
const postEntityResponse = {
|
|
|
|
users: [{ id: 1, name: "John Smith" }],
|
|
|
|
};
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
const putEntityResponse = {
|
|
|
|
users: [{ id: 2, name: "John Foo" }],
|
|
|
|
};
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
const deleteEntityResponse = null;
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("get should return a list of results and return with HTTP code 200", (done) => {
|
|
|
|
Api.get("foo")
|
|
|
|
.then((response) => {
|
|
|
|
assert.equal(200, response.status);
|
|
|
|
assert.deepEqual(getCollectionResponse, response.data);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
done(error);
|
|
|
|
});
|
|
|
|
});
|
2019-08-13 09:45:10 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("get should return one item and return with HTTP code 200", (done) => {
|
|
|
|
Api.get("foo/123")
|
|
|
|
.then((response) => {
|
|
|
|
assert.equal(200, response.status);
|
|
|
|
assert.deepEqual(getEntityResponse, response.data);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
done(error);
|
|
|
|
});
|
|
|
|
});
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("post should create one item and return with HTTP code 201", (done) => {
|
|
|
|
Api.post("foo", postEntityResponse)
|
|
|
|
.then((response) => {
|
|
|
|
assert.equal(201, response.status);
|
|
|
|
assert.deepEqual(postEntityResponse, response.data);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
done(error);
|
|
|
|
});
|
|
|
|
});
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("put should update one item and return with HTTP code 200", (done) => {
|
|
|
|
Api.put("foo/2", putEntityResponse)
|
|
|
|
.then((response) => {
|
|
|
|
assert.equal(200, response.status);
|
|
|
|
assert.deepEqual(putEntityResponse, response.data);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
done(error);
|
|
|
|
});
|
|
|
|
});
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("delete should delete one item and return with HTTP code 204", (done) => {
|
|
|
|
Api.delete("foo/2", deleteEntityResponse)
|
|
|
|
.then((response) => {
|
|
|
|
assert.equal(204, response.status);
|
|
|
|
assert.deepEqual(deleteEntityResponse, response.data);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
done(error);
|
|
|
|
});
|
|
|
|
});
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2021-07-12 19:25:37 +02:00
|
|
|
/*
|
2021-01-09 04:41:33 +01:00
|
|
|
it("get error", function () {
|
|
|
|
return Api.get("error")
|
|
|
|
.then(function (m) {
|
2021-07-12 19:25:37 +02:00
|
|
|
return Promise.reject("error expected");
|
2021-01-09 04:41:33 +01:00
|
|
|
})
|
|
|
|
.catch(function (m) {
|
|
|
|
assert.equal(m.message, "Request failed with status code 401");
|
2021-07-12 19:25:37 +02:00
|
|
|
return Promise.resolve();
|
2021-01-09 04:41:33 +01:00
|
|
|
});
|
|
|
|
});
|
2021-07-12 19:25:37 +02:00
|
|
|
*/
|
2019-05-20 20:06:26 +02:00
|
|
|
});
|