Skip to content

Commit

Permalink
Add a test to assert that canceling GETs can't instead cancel DELETEs
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed May 25, 2018
1 parent 73aa3aa commit f160f70
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion ui/tests/unit/adapters/job-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import EmberObject from '@ember/object';
import { run } from '@ember/runloop';
import { assign } from '@ember/polyfills';
import { test } from 'ember-qunit';
Expand All @@ -10,8 +11,12 @@ moduleForAdapter('job', 'Unit | Adapter | Job', {
'adapter:job',
'service:token',
'service:system',
'model:namespace',
'model:allocation',
'model:deployment',
'model:evaluation',
'model:job-summary',
'model:job-version',
'model:namespace',
'adapter:application',
'service:watchList',
],
Expand Down Expand Up @@ -292,6 +297,36 @@ test('requests can be canceled even if multiple requests for the same URL were m
});
});

test('canceling a find record request will never cancel a request with the same url but different method', function(assert) {
const { pretender } = this.server;
const jobId = JSON.stringify(['job-1', 'default']);

pretender.get('/v1/job/:id', () => [200, {}, '{}'], true);
pretender.delete('/v1/job/:id', () => [204, {}, ''], 200);

this.subject().findRecord(null, { modelName: 'job' }, jobId, {
reload: true,
adapterOptions: { watch: true },
});

this.subject().stop(EmberObject.create({ id: jobId }));

const { request: getXHR } = pretender.requestReferences[0];
const { request: deleteXHR } = pretender.requestReferences[1];
assert.equal(getXHR.status, 0, 'Get request is still pending');
assert.equal(deleteXHR.status, 0, 'Delete request is still pending');

// Schedule the cancelation before waiting
run.next(() => {
this.subject().cancelFindRecord('job', jobId);
});

return wait().then(() => {
assert.ok(getXHR.aborted, 'Get request was aborted');
assert.notOk(deleteXHR.aborted, 'Delete request was aborted');
});
});

function makeMockModel(id, options) {
return assign(
{
Expand Down

0 comments on commit f160f70

Please sign in to comment.