-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdelete-definition-service.spec.ts
More file actions
82 lines (67 loc) · 2.09 KB
/
delete-definition-service.spec.ts
File metadata and controls
82 lines (67 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as chai from "chai";
import * as proxyquire from "proxyquire";
import * as sinon from "sinon";
import * as sinonChai from "sinon-chai";
import * as nock from "nock";
const expect = chai.expect;
chai.use(sinonChai);
describe("Test Delete Definition service", () => {
const deleteDefinitionUrl = "http://localhost:4451/api/draft";
let deleteDefinition;
let req;
beforeEach(() => {
req = {
accessToken: "userAuthToken",
body: {
definitionVersion: 1,
jurisdictionId: "TEST",
},
serviceAuthToken: "serviceAuthToken",
session: { jurisdiction: "TEST" },
};
const config = {
get: sinon.stub(),
};
config.get.withArgs("adminWeb.deletedefinition_url").returns(deleteDefinitionUrl);
deleteDefinition = proxyquire("../../main/service/delete-definition-service", {
config,
}).deleteDefinition;
});
it("should return an HTTP 204 status and success message", (done) => {
const expectedResult = "Definition deleted successfully";
nock("http://localhost:4451")
.delete(`/api/draft/${req.body.jurisdictionId}/${req.body.definitionVersion}`)
.reply(204, expectedResult);
deleteDefinition(req).then((res) => {
try {
expect(res.status).to.equal(204);
expect(res.text).to.equal(expectedResult);
done();
} catch (e) {
done(e);
}
}).catch((err) => {
done(err);
});
});
it("should return an HTTP 403 status and error message", (done) => {
req.serviceAuthToken = "invalid_token";
const expectedResult = {
error: "Forbidden",
message: "Access Denied",
};
nock("http://localhost:4451")
.delete(`/api/draft/${req.body.jurisdictionId}/${req.body.definitionVersion}`)
.reply(403, expectedResult);
deleteDefinition(req).catch((err) => {
try {
expect(err.status).to.equal(403);
expect(err.response.body.error).to.equal(expectedResult.error);
expect(err.response.body.message).to.equal(expectedResult.message);
done();
} catch (e) {
done(e);
}
});
});
});