Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(function() {
account = {
Name: "Adventure Works"
};
contact = {
FirstName: "Joe"
};
WebApiClient.Configure(defaults);
xhr = sinon.fakeServer.create();
xhr.autoRespond = true;
// Respond to Create Request for account with No-Content response and created entity url in header
var createAccountUrl = new RegExp(RegExp.escape(fakeUrl + "/api/data/v8.0/accounts"));
xhr.respondWith("POST", createAccountUrl,
[204, { "Content-Type": "application/json", "OData-EntityId": "Fake-Account-Url" }, JSON.stringify(successMock)]
);
// Respond to create request with return=representation
var createLeadUrlRepresentation = new RegExp(RegExp.escape(fakeUrl + "/api/data/v8.0/leads"));
xhr.respondWith("POST", createLeadUrlRepresentation,
[201, { "Content-Type": "application/json" }, JSON.stringify(account)]
);
// Respond to Retrieve by id Request for account
var retrieveAccountByIdUrl = RegExp.escape(fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000001)");
export const init = () => {
const server = sinon.fakeServer.create();
server.respondImmediately = true;
// We make requests to APIs which don't impact the UX, e.g. UI metric telemetry,
// and we can mock them all with a 200 instead of mocking each one individually.
server.respondWith([200, {}, '']);
return {
server,
httpRequestsMockHelpers: registerHttpRequestMockHelpers(server),
};
};
u.test("decodes polyline geometries", function (v) {
var server = sinon.fakeServer.create();
var directions = L.mapbox.directions({accessToken: 'key'});
directions.on('load', function (e) {
v.deepEqual(e.routes[0].geometry, {
type: 'LineString',
coordinates: [[-120.2, 38.5], [-120.95, 40.7], [-126.453, 43.252]]
});
v.end();
server.restore();
});
directions
.setOrigin(L.latLng(1, 2))
.setDestination(L.latLng(3, 4))
.query();
test.before(() => {
sinon.xhr.supportsCORS = true
server = sinon.fakeServer.create({
respondImmediately: true
})
server.respondWith('POST', /^.*\?uploads.*$/, (xhr) => {
requestHeaders.initiate = xhr.requestHeaders
xhr.respond(200, CONTENT_TYPE_XML, initResponse(AWS_BUCKET, AWS_UPLOAD_KEY))
})
server.respondWith('PUT', /^.*$/, (xhr) => {
requestHeaders.upload = xhr.requestHeaders
xhr.respond(200)
})
server.respondWith('POST', /.*\?uploadId.*$/, (xhr) => {
requestHeaders.complete = xhr.requestHeaders
xhr.respond(200, CONTENT_TYPE_XML, completeResponse(AWS_BUCKET, AWS_UPLOAD_KEY))
})
test.before(() => {
sinon.xhr.supportsCORS = true
server = serverCommonCase()
global.XMLHttpRequest = sinon.fakeServer.xhr
})
test.beforeEach((t) => {
t.context.requestedAwsObjectKey = randomAwsKey()
t.context.baseAddConfig = {
name: t.context.requestedAwsObjectKey,
file: new File({
path: '/tmp/file',
size: 6000000,
name: randomAwsKey()
})
}
t.context.cryptoMd5 = sinon.spy(function (data) { return 'md5Checksum'; })
headStatus = 200
server = sinon.fakeServer.create({
respondImmediately: true
})
headersForMethod = function(method, urlRegex) {
var r = urlRegex || /./
for (var i = 0; i < server.requests.length; i++) {
var xhr = server.requests[i]
if (xhr.method === method && xhr.url.match(r)) {
return xhr.requestHeaders
}
}
return {}
}
t.context.testBase = async function (addConfig, evapConfig) {
t.context.deferred = defer();
test.cb('sends request to URL', t => {
const server = sinon.fakeServer.create();
const url = 'http://test.test/';
const btn = new MicroFeedbackButton({url});
const response = {
backend: {name: 'github', version: '1.2.3'},
result: {},
};
server.respondWith('POST', url, [
201,
{'Content-Type': 'application/json'},
JSON.stringify(response),
]);
syn.click(btn.el, () => {
const input = $('.swal2-textarea');
syn.type(input, 'foo bar baz', () => {
const submit = $('button.swal2-confirm');
syn.click(submit).delay(() => {
it.skip('accepts an ajax timeout value which will terminate the request if it is not completed', function (done) {
this.server.restore();
this.server = sinon.fakeServer.create();
this.server.respondWith([200, {}, '']);
AJAXDriver.request({
url: TEST_SERVER_URL,
timeout: 50,
graphQL: this.fakeGraphQL,
metadata: this.fakeMetadata
}, function callback(err) {
expect(err).to.not.eql(null);
done();
});
setTimeout(function () {
this.server.respond();
}.bind(this), 1000);
});
test("create must post a resource to the server and add it to the store on success", function (t) {
var server = sinon.fakeServer.create({ autoRespond: false });
var adapter = new Store.AjaxAdapter();
var store = new Store(adapter);
t.plan(3);
t.timeoutAfter(1000);
store.define("products", {
title: Store.attr()
});
server.respondWith("POST", "/products", function (request) {
t.deepEqual(JSON.parse(request.requestBody), {
data: {
type: "products",
attributes: {
title: "My Book"
},
relationships: {}
}
before(() => { server = sinon.fakeServer.create(); });
after(() => { server.restore() });