Browse Source

Merge branch 'dev' of https://github.com/artf/grapesjs into dev

pull/1730/head
Artur Arseniev 7 years ago
parent
commit
8af686cb7f
  1. 4
      src/storage_manager/config/config.js
  2. 14
      src/storage_manager/model/RemoteStorage.js
  3. 45
      test/specs/storage_manager/model/Models.js

4
src/storage_manager/config/config.js

@ -53,5 +53,7 @@ module.exports = {
// set contentType paramater of $.ajax
// true: application/json; charset=utf-8'
// false: 'x-www-form-urlencoded'
contentTypeJson: false
contentTypeJson: false,
credentials: 'include'
};

14
src/storage_manager/model/RemoteStorage.js

@ -10,7 +10,8 @@ module.exports = require('backbone').Model.extend({
params: {},
beforeSend() {},
onComplete() {},
contentTypeJson: false
contentTypeJson: false,
credentials: 'include'
},
/**
@ -113,7 +114,7 @@ module.exports = require('backbone').Model.extend({
}
fetchOptions = {
method: opts.method || 'post',
credentials: 'include',
credentials: this.get('credentials'),
headers
};
@ -124,11 +125,10 @@ module.exports = require('backbone').Model.extend({
this.onStart();
this.fetch(url, fetchOptions)
.then(
res =>
((res.status / 200) | 0) == 1
? res.text()
: res.text().then(text => Promise.reject(text))
.then(res =>
((res.status / 200) | 0) == 1
? res.text()
: res.text().then(text => Promise.reject(text))
)
.then(text => this.onResponse(text, clb))
.catch(err => this.onError(err, clbErr));

45
test/specs/storage_manager/model/Models.js

@ -96,6 +96,51 @@ module.exports = {
expect(callResult.called).toEqual(true);
expect(callResult.firstCall.args[0]).toEqual(endpointLoad);
});
test("Load data with credentials option as 'include' by default", () => {
obj.load(['item1', 'item2']);
const callResult = obj.fetch;
expect(callResult.called).toEqual(true);
expect(callResult.firstCall.args[1]).toMatchObject({
credentials: 'include'
});
});
test("Store data with credentials option as 'include' by default", () => {
obj.store(data);
const callResult = obj.fetch;
expect(callResult.called).toEqual(true);
expect(callResult.firstCall.args[1]).toMatchObject({
credentials: 'include'
});
});
test('Store data with credentials option as false ', () => {
obj = new RemoteStorage({ ...storageOptions, credentials: false });
sinon
.stub(obj, 'fetch')
.returns(Promise.resolve(mockResponse({ data: 1 })));
obj.store(data);
const callResult = obj.fetch;
expect(callResult.called).toEqual(true);
expect(callResult.firstCall.args[1]).toMatchObject({
credentials: false
});
});
test('Load data with credentials option as false', () => {
obj = new RemoteStorage({ ...storageOptions, credentials: false });
sinon
.stub(obj, 'fetch')
.returns(Promise.resolve(mockResponse({ data: 1 })));
obj.load(['item1', 'item2']);
const callResult = obj.fetch;
expect(callResult.called).toEqual(true);
expect(callResult.firstCall.args[1]).toMatchObject({
credentials: false
});
});
});
}
};

Loading…
Cancel
Save