This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
/
attachment.js
83 lines (76 loc) · 2.36 KB
/
attachment.js
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
83
var desk = require('../')
, should = require('should')
, replay = require('replay')
, fs = require('fs')
;
replay.fixtures = __dirname + '/fixtures';
replay.mode = 'record';
replay.request_headers = [/^accept/, /^content-type/, /^host/, /^if-/, /^x-/];
try {
config = require('../config/test');
} catch (err) {
config = {
subdomain: 'devel',
username: 'devel@example.com',
password: '12345'
}
}
function createClient() {
return desk.createClient({
subdomain: config.subdomain ,
username: config.username,
password: config.password
})
}
// check if the hack works
describe('Attachment', function() {
describe('create', function() {
it('creates a new attachment on a case', function(done) {
var client = createClient();
client.cases(function(err, cases) {
cases[0].attachments().create({
file_name: 'GlasKunst.jpg',
content_type: 'image/jpeg',
content: fs.readFileSync(__dirname + '/fixtures/attachment.jpg', 'base64')
}, function(err, attachment) {
attachment.getFileName().should.equal('GlasKunst.jpg');
attachment.getUrl().should.not.equal('');
done();
});
});
})
})
describe('delete', function() {
it('deletes an attachment from a case - currently not working', function(done) {
var client = createClient();
client.cases(function(err, cases) {
cases[0].attachments(function(err, attachments) {
attachments[0].destroy(function(err) {
should.not.exist(err);
done();
})
})
})
})
})
// describe('update', function() {
// it('updates attachments on cases', function(done) {
// var client = createClient();
// client.cases(function(err, cases) {
// // cases[0] is a phone call
// cases[1].attachments().create({
// body: 'some text for this attachment',
// direction: 'out',
// status: 'draft'
// }, function(err, attachment) {
// attachment.setBody('some other text for this attachment');
// attachment.update(function(err, attachment) {
// attachment.getBody().should.equal('some other text for this attachment');
// attachment.getDirection().should.equal('out');
// done();
// });
// });
// });
// })
// })
})