forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchRequestSpec.js
More file actions
97 lines (92 loc) · 3.78 KB
/
FetchRequestSpec.js
File metadata and controls
97 lines (92 loc) · 3.78 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
import { FetchRequest, isCORS, setCORS, setFetch } from '../../../src/common//util/FetchRequest';
describe('FetchRequest', () => {
const defaultval = SuperMap.Util.RequestJSONPPromise.limitLength;
const defaltCors = isCORS();
let fetch;
beforeAll(() => {
fetch = jasmine.createSpy('fetch').and.resolveTo({ success: 'ok' });
setFetch(fetch);
});
xit('RequestJSONPPromise', () => {
var url = 'http://test.supermap.io/examples/leaflet/editor.html#addressMatchService';
var params;
var options;
spyOn(SuperMap.Util.RequestJSONPPromise, 'issue').and.callFake(() => {});
setCORS(false);
FetchRequest.get(url, params, options);
expect(SuperMap.Util.RequestJSONPPromise.issue).toHaveBeenCalled();
var paramsde = {
completeLineSymbolDisplayed: false,
visible: true
};
SuperMap.Util.RequestJSONPPromise.limitLength = 5;
var deleteUri =
'http://test/GUID=PCdd8b1ab00896b3a7a&app=ydrive&cl=desktop?leftBottom%22%20:%20%7B%22x%22:NaN,%22y%22:NaN%7D,%22rightTo';
FetchRequest.delete(deleteUri, paramsde, options);
expect(SuperMap.Util.RequestJSONPPromise.issue.calls.count()).toBe(2);
FetchRequest.post(deleteUri, paramsde, options);
expect(SuperMap.Util.RequestJSONPPromise.issue.calls.count()).toBe(3);
SuperMap.Util.RequestJSONPPromise.limitLength = 180;
FetchRequest.put(deleteUri, paramsde, options);
expect(SuperMap.Util.RequestJSONPPromise.issue.calls.count()).toBe(4);
setCORS(defaltCors);
});
it('Get_arrayObject', () => {
var url = 'http://test.supermap.io/examples/leaflet/editor.html#addressMatchService';
var params = {
tags: ['bb', 'aa'],
aa: { aa: 1 }
};
setCORS(true);
spyOn(FetchRequest, '_fetch').and.callFake((url) => {
expect(url).toContain('%5B%22bb%22%2C%22aa%22%5D');
expect(url).toContain('%7B%22aa%22%3A1%7D');
});
FetchRequest.get(url, params);
expect(FetchRequest._fetch.calls.count()).toBe(1);
});
it('Get_withCredentials_true', () => {
var url = 'http://test.supermap.io';
setCORS(true);
FetchRequest.get(url, null, { withCredentials: true });
expect(fetch).toHaveBeenCalledWith('http://test.supermap.io.json', {
method: 'GET',
body: undefined,
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
credentials: 'include',
mode: 'cors',
timeout: 45000
});
});
it('Get_withCredentials_false', () => {
var url = 'http://test.supermap.io';
setCORS(true);
FetchRequest.get(url, null, { withCredentials: false });
expect(fetch).toHaveBeenCalledWith('http://test.supermap.io.json', {
method: 'GET',
body: undefined,
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
credentials: 'omit',
mode: 'cors',
timeout: 45000
});
});
it('Get_withCredentials_any', () => {
var url = 'http://test.supermap.io';
setCORS(true);
FetchRequest.get(url, null, { withCredentials: 'depends' });
expect(fetch).toHaveBeenCalledWith('http://test.supermap.io.json', {
method: 'GET',
body: undefined,
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
credentials: 'same-origin',
mode: 'cors',
timeout: 45000
});
});
afterAll(() => {
SuperMap.Util.RequestJSONPPromise.limitLength = defaultval;
setCORS(defaltCors);
setFetch(window.fetch);
});
});