forked from Saleslogix/SDataJavaScriptClientLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDataServiceTests.js
More file actions
99 lines (81 loc) · 4 KB
/
Copy pathSDataServiceTests.js
File metadata and controls
99 lines (81 loc) · 4 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
define('spec/SDataServiceTests', [], function() {
describe('SDataService', function() {
it('can set available url properties via constructor', function() {
var service = new Sage.SData.Client.SDataService({
protocol: 'https',
serverName: 'localhost',
port: 8080,
virtualDirectory: 'sdata',
applicationName: 'aw',
contractName: 'dynamic',
dataSet: 'alpha',
includeContent: true
});
expect(service.uri.build()).toEqual("https://localhost:8080/sdata/aw/dynamic/alpha?_includeContent=true");
});
it('can be compact', function() {
var service = new Sage.SData.Client.SDataService({
protocol: 'https',
serverName: 'localhost',
port: 8080,
virtualDirectory: 'sdata',
applicationName: 'aw',
contractName: 'dynamic',
dataSet: 'alpha',
compact: true
});
expect(service.uri.build()).toEqual("https://localhost:8080/sdata/aw/dynamic/alpha?_compact=true");
});
it('can set available url properties via url passed to constructor', function() {
var service = new Sage.SData.Client.SDataService("https://localhost:8080/sdata/aw/dynamic/alpha");
expect(service.uri.build()).toEqual("https://localhost:8080/sdata/aw/dynamic/alpha");
});
it('can set credentials via arguments passed to constructor', function() {
var service = new Sage.SData.Client.SDataService("https://localhost:8080/sdata/aw/dynamic/alpha", "admin", "password");
expect(service.uri.build()).toEqual("https://localhost:8080/sdata/aw/dynamic/alpha");
expect(service.getUserName()).toEqual("admin");
expect(service.getPassword()).toEqual("password");
});
it('can mix and match url properties via object passed to constructor', function() {
var service = new Sage.SData.Client.SDataService({
url: "https://localhost:8080/sdata/aw/dynamic/alpha",
applicationName: "sample",
dataSet: "omega",
userName: "user",
password: "password"
}, "admin");
expect(service.uri.build()).toEqual("https://localhost:8080/sdata/sample/dynamic/omega");
expect(service.getUserName()).toEqual("admin");
expect(service.getPassword()).toEqual("password");
});
it('does provide data set segment to requests', function() {
var service = new Sage.SData.Client.SDataService({
serverName: 'localhost',
virtualDirectory: 'sdata',
applicationName: 'aw',
contractName: 'dynamic',
dataSet: 'alpha'
});
var request = new Sage.SData.Client.SDataResourceCollectionRequest(service)
.setResourceKind('employees');
expect(request.build()).toEqual("http://localhost/sdata/aw/dynamic/alpha/employees");
});
it('supports extension of the accept header', function() {
spyOn(Sage.SData.Client.Ajax, 'request');
var service = new Sage.SData.Client.SDataService({
serverName: 'localhost',
virtualDirectory: 'sdata',
applicationName: 'aw',
contractName: 'dynamic'
});
var request = new Sage.SData.Client.SDataResourceCollectionRequest(service)
.setResourceKind('employees')
.setAccept('view=other');
request.read();
(function(options) {
expect(options).toHaveProperty('headers');
expect(options).toHaveProperty('headers.Accept', 'application/atom+xml;type=feed;view=other,*/*;view=other');
})(Sage.SData.Client.Ajax.request.calls.mostRecent().args[0]);
});
});
});