Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
xit(`should send HTTP ping`, async () => {
await sleep(pingIntervalS*2*1000 + 10);
// ping
expect(fetchMock.calls('ping')).to.be.lengthOf.at.least(1, "expected `ping` to be fetched");
}).timeout(pingIntervalS*3*1000);
} else {
it('should send `HTTP PATCH _remoteUrl_/reconnect` with pending changes in body', async () => {
await sleep(pingIntervalS*1000 + 10);
// establish
expect(fetchMock.calls('establish')).to.be.lengthOf(1, "expected `establish` to be fetched once");
expect(fetchMock.called(/testURL/)).to.be.ok;
// reconnect
expect(fetchMock.calls('reconnect')).to.be.lengthOf(1, "expected `reconnect` to be fetched once");
const [reconnectURL, reconnectCall] = fetchMock.lastCall();
expect(reconnectURL).to.equal(getTestURL('testURL')+'/reconnect');
expect(reconnectCall).to.have.property('body','[[{"op":"replace","path":"/_ver#c$","value":1},{"op":"test","path":"/_ver#s"},{"op":"replace","path":"/hello","value":"OT"}]]');
expect(reconnectCall).to.have.property('method','PATCH');
expect(reconnectCall.headers).to.have.property('Content-Type','application/json-patch+json');
expect(reconnectCall.headers).to.have.property('Accept','application/json');
}).timeout(pingIntervalS*2*1000);
describe('when server responds to `/reconnect`', () => {
it(`should send empty patch (\`[]\`) after ${pingIntervalS} seconds after sending local change`, async () => {
// establish
expect(fetchMock.calls('establish')).to.be.lengthOf(1);
expect(fetchMock.called(/testURL/)).to.be.ok;
await sleep(10);
// change
palindrom.obj.hello = "Ping Machine";
await sleep(10);
expect(fetchMock.calls('patch')).to.be.lengthOf(1, 'should send patch request just after a change');
await sleep(pingIntervalS*1000 + 10);
// // ping
expect(fetchMock.calls('ping')).to.be.lengthOf(1, 'should send ping request `pingIntervalS` after a change');
const [pingURL, pingCall] = fetchMock.lastCall();
expect(pingURL).to.equal(getTestURL('testURL'));
expect(pingCall).to.have.property('body','[]');
expect(pingCall).to.have.property('method','PATCH');
expect(pingCall.headers).to.have.property('Content-Type','application/json-patch+json');
expect(pingCall.headers).to.have.property('Accept','application/json-patch+json');
}).timeout(pingIntervalS*2*1000);
describe('and server does not respond to send ping within `pingIntervalS`', () => {
it(`${verb} passes custom config`, () => {
fetchMock.once(endpoint, {});
transport.request(verb, endpoint, {}, config);
expect(fetchMock.calls()[0][1]).toEqual(expected);
});
});
it('calls fetch() with correct input url', () => {
const path = 'https://wp.com/wp-json/wp/v1/posts';
fetchMock.once(path, {});
transport.request(path);
expect(fetchMock.calls()[0][0]).toEqual(path);
});
it("then the client should not have made a fetch request", () => {
expect(fetchMock.calls().matched).to.have.lengthOf(0);
});
}
it("then the client should have made no fetch request", () => {
expect(fetchMock.calls().unmatched).to.have.lengthOf(0);
});
post(id: "1") @jsonapi(path: "/post/{args.id}") {
id
title
}
}
`;
await makePromise(
execute(link, {
operationName: 'postTitle',
query: postTitleQuery,
variables: { id: '1' },
}),
);
const requestCall = fetchMock.calls('/api/post/1')[0];
expect(orderDupPreservingFlattenedHeaders(requestCall[1])).toEqual([
'accept: application/vnd.api+json',
'authorization: 1234',
'context: context',
'setup: setup, in-context duplicate setup',
]);
});
operationName: 'posts',
query: postsQuery,
};
const link1 = new JsonApiLink({ uri: '/api' });
await makePromise(execute(link1, operation));
const link2 = new JsonApiLink({
uri: '/api',
headers: {
Accept: 'text/plain',
},
});
await makePromise(execute(link2, operation));
const requestCalls = fetchMock.calls('/api/posts');
expect(orderDupPreservingFlattenedHeaders(requestCalls[0][1])).toEqual([
'accept: application/vnd.api+json',
]);
expect(orderDupPreservingFlattenedHeaders(requestCalls[1][1])).toEqual([
'accept: text/plain',
]);
});
return makeRequest().then(() => {
expect(fetchMock.calls(stopQueryEndpoint)).toHaveLength(1);
});
});