@tiledesk/tiledesk-server 2.10.33 → 2.10.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,156 @@
1
+ //During the test the env variable is set to test
2
+ process.env.NODE_ENV = 'test';
3
+
4
+ const userService = require('../services/userService');
5
+ const projectService = require('../services/projectService');
6
+ const leadService = require('../services/leadService');
7
+
8
+ //Require the dev-dependencies
9
+ let chai = require('chai');
10
+ let chaiHttp = require('chai-http');
11
+ let server = require('../app');
12
+ let should = chai.should();
13
+ var expect = chai.expect;
14
+ var assert = chai.assert;
15
+
16
+
17
+ let log = false;
18
+
19
+ chai.use(chaiHttp);
20
+
21
+
22
+ describe('LeadRoute', () => {
23
+
24
+ // mocha test/leadRoute.js --grep 'add-tags-to-lead'
25
+ it('add-tags-to-lead', function (done) {
26
+
27
+ var email = "test-request-create-" + Date.now() + "@email.com";
28
+ var pwd = "pwd";
29
+ var userid = "5badfe5d553d1844ad654072";
30
+
31
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
32
+ projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
33
+ var attr = { myprop: 123 };
34
+ leadService.create("fullname", "email@email.com", savedProject._id, userid, attr).then(function (savedLead) {
35
+
36
+ savedLead.should.have.property('_id').not.eql(null);
37
+ let lead_id = savedLead._id;
38
+
39
+ let tags = [ "tag1", "tag2" ]
40
+
41
+ // First Step: add 2 tags on a conversation no tagged at all
42
+ chai.request(server)
43
+ .put('/' + savedProject._id + '/leads/' + lead_id + '/tag')
44
+ .auth(email, pwd)
45
+ .send(tags)
46
+ .end((err, res) => {
47
+
48
+ if (err) { console.log("err: ", err) };
49
+ if (log) { console.log("res.body: ", res.body) };
50
+
51
+ res.should.have.status(200);
52
+ res.body.should.be.a('object');
53
+ expect(res.body.tags).to.have.length(2);
54
+ expect(res.body.tags[0]).to.equal('tag1');
55
+ expect(res.body.tags[1]).to.equal('tag2');
56
+
57
+ let tags2 = [ "tag2", "tag3" ]
58
+
59
+ // Second Step: add more 2 tags of which one already existant in the conversation
60
+ chai.request(server)
61
+ .put('/' + savedProject._id + '/leads/' + lead_id + '/tag')
62
+ .auth(email, pwd)
63
+ .send(tags2)
64
+ .end((err, res) => {
65
+
66
+ if (err) { console.log("err: ", err) };
67
+ if (log) { console.log("res.body: ", res.body) };
68
+
69
+ res.should.have.status(200);
70
+ res.body.should.be.a('object');
71
+ expect(res.body.tags).to.have.length(3);
72
+ expect(res.body.tags[0]).to.equal('tag1');
73
+ expect(res.body.tags[1]).to.equal('tag2');
74
+ expect(res.body.tags[2]).to.equal('tag3');
75
+
76
+ done();
77
+ })
78
+
79
+ })
80
+
81
+ }).catch(function (err) {
82
+ winston.error("test reject", err);
83
+ assert.isNotOk(err, 'Promise error');
84
+ done();
85
+ });
86
+ })
87
+
88
+ })
89
+
90
+ }).timeout(5000)
91
+
92
+ // mocha test/leadRoute.js --grep 'remove-tags-from-lead'
93
+ it('remove-tags-from-lead', function (done) {
94
+
95
+ var email = "test-request-create-" + Date.now() + "@email.com";
96
+ var pwd = "pwd";
97
+ var userid = "5badfe5d553d1844ad654072";
98
+
99
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
100
+ projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
101
+ var attr = { myprop: 123 };
102
+ leadService.create("fullname", "email@email.com", savedProject._id, userid, attr).then(function (savedLead) {
103
+
104
+ savedLead.should.have.property('_id').not.eql(null);
105
+ let lead_id = savedLead._id;
106
+
107
+ let tags = [ "tag1", "tag2" ]
108
+
109
+ // First Step: add 2 tags on a conversation no tagged at all
110
+ chai.request(server)
111
+ .put('/' + savedProject._id + '/leads/' + lead_id + '/tag')
112
+ .auth(email, pwd)
113
+ .send(tags)
114
+ .end((err, res) => {
115
+
116
+ if (err) { console.log("err: ", err) };
117
+ if (log) { console.log("res.body: ", res.body) };
118
+
119
+ res.should.have.status(200);
120
+ res.body.should.be.a('object');
121
+ expect(res.body.tags).to.have.length(2);
122
+ expect(res.body.tags[0]).to.equal('tag1');
123
+ expect(res.body.tags[1]).to.equal('tag2');
124
+
125
+ let tag_to_remove = res.body.tags[1];
126
+
127
+ chai.request(server)
128
+ .delete('/' + savedProject._id + '/leads/' + lead_id + '/tag/' + tag_to_remove)
129
+ .auth(email, pwd)
130
+ .end((err, res) => {
131
+
132
+ if (err) { console.log("err: ", err) };
133
+ if (log) { console.log("res.body: ", res.body) };
134
+
135
+ res.should.have.status(200);
136
+ res.body.should.be.a('object');
137
+ expect(res.body.tags).to.have.length(1);
138
+ expect(res.body.tags[0]).to.equal('tag1');
139
+
140
+ done();
141
+
142
+ })
143
+
144
+ })
145
+
146
+ }).catch(function (err) {
147
+ winston.error("test reject", err);
148
+ assert.isNotOk(err, 'Promise error');
149
+ done();
150
+ });
151
+ })
152
+
153
+ })
154
+
155
+ }).timeout(5000)
156
+ })