Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP] re-use test setup to assert correct call to adapter.ajax #4018

Merged
merged 1 commit into from
Dec 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 24 additions & 54 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,12 @@ test("findRecord - payload with a serializer-specified attribute mapping", funct

if (isEnabled('ds-finder-include')) {
test("findRecord - passes `include` as a query parameter to ajax", function(assert) {
adapter.ajax = function(url, verb, hash) {
assert.deepEqual(hash.data, { include: 'comments' },
'`include` parameter sent to adapter.ajax');

return run(Ember.RSVP, 'resolve', {
post: { id: 1, name: 'Rails is very expensive sushi' }
});
};
ajaxResponse({
post: { id: 1, name: 'Rails is very expensive sushi' }
});

run(store, 'findRecord', 'post', 1, { include: 'comments' }).then(assert.wait(function() {
// Noop
assert.deepEqual(passedHash.data, { include: 'comments' }, '`include` parameter sent to adapter.ajax');
}));
});
}
Expand Down Expand Up @@ -1048,17 +1043,12 @@ test("findAll - passes buildURL the requestType", function(assert) {

if (isEnabled('ds-finder-include')) {
test("findAll - passed `include` as a query parameter to ajax", function(assert) {
adapter.ajax = function(url, verb, hash) {
assert.deepEqual(hash.data, { include: 'comments' },
'`include` params sent to adapter.ajax');

return run(Ember.RSVP, 'resolve', {
posts: [{ id: 1, name: 'Rails is very expensive sushi' }]
});
};
ajaxResponse({
posts: [{ id: 1, name: 'Rails is very expensive sushi' }]
});

run(store, 'findAll', 'post', { include: 'comments' }).then(assert.wait(function() {
// Noop
assert.deepEqual(passedHash.data, { include: 'comments' }, '`include` params sent to adapter.ajax');
}));
});
}
Expand Down Expand Up @@ -1117,18 +1107,12 @@ test("findAll - data is normalized through custom serializers", function(assert)
});

test("query - if `sortQueryParams` option is not provided, query params are sorted alphabetically", function(assert) {
adapter.ajax = function(url, verb, hash) {
passedUrl = url;
passedVerb = verb;
passedHash = hash;

assert.deepEqual(Object.keys(hash.data), ["in", "order", "params", "wrong"], 'query params are received in alphabetical order');

return run(Ember.RSVP, 'resolve', { posts: [{ id: 1, name: "Rails is very expensive sushi" }] });
};
ajaxResponse({
posts: [{ id: 1, name: "Rails is very expensive sushi" }]
});

store.query('post', { "params": 1, "in": 2, "wrong": 3, "order": 4 }).then(assert.wait(function() {
// Noop
assert.deepEqual(Object.keys(passedHash.data), ["in", "order", "params", "wrong"], 'query params are received in alphabetical order');
}));
});

Expand All @@ -1137,45 +1121,31 @@ test("query - passes buildURL the requestType", function(assert) {
return "/" + requestType + "/posts";
};

adapter.ajax = function(url, verb, hash) {
assert.equal(url, '/query/posts');

return run(Ember.RSVP, 'resolve', { posts: [{ id: 1, name: "Rails is very expensive sushi" }] });
};
ajaxResponse({
posts: [{ id: 1, name: "Rails is very expensive sushi" }]
});

store.query('post', { "params": 1, "in": 2, "wrong": 3, "order": 4 }).then(assert.wait(function() {
// NOOP
assert.equal(passedUrl, '/query/posts');
}));
});

test("query - if `sortQueryParams` is falsey, query params are not sorted at all", function(assert) {
adapter.ajax = function(url, verb, hash) {
passedUrl = url;
passedVerb = verb;
passedHash = hash;

assert.deepEqual(Object.keys(hash.data), ["params", "in", "wrong", "order"], 'query params are received in their original order');

return run(Ember.RSVP, 'resolve', { posts: [{ id: 1, name: "Rails is very expensive sushi" }] });
};
ajaxResponse({
posts: [{ id: 1, name: "Rails is very expensive sushi" }]
});

adapter.sortQueryParams = null;

store.query('post', { "params": 1, "in": 2, "wrong": 3, "order": 4 }).then(assert.wait(function() {
// Noop
assert.deepEqual(Object.keys(passedHash.data), ["params", "in", "wrong", "order"], 'query params are received in their original order');
}));
});

test("query - if `sortQueryParams` is a custom function, query params passed through that function", function(assert) {
adapter.ajax = function(url, verb, hash) {
passedUrl = url;
passedVerb = verb;
passedHash = hash;

assert.deepEqual(Object.keys(hash.data), ["wrong", "params", "order", "in"], 'query params are received in reverse alphabetical order');

return run(Ember.RSVP, 'resolve', { posts: [{ id: 1, name: "Rails is very expensive sushi" }] });
};
ajaxResponse({
posts: [{ id: 1, name: "Rails is very expensive sushi" }]
});

adapter.sortQueryParams = function(obj) {
var sortedKeys = Object.keys(obj).sort().reverse();
Expand All @@ -1189,7 +1159,7 @@ test("query - if `sortQueryParams` is a custom function, query params passed thr
};

store.query('post', { "params": 1, "in": 2, "wrong": 3, "order": 4 }).then(assert.wait(function() {
// Noop
assert.deepEqual(Object.keys(passedHash.data), ["wrong", "params", "order", "in"], 'query params are received in reverse alphabetical order');
}));
});

Expand Down