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

more cleanup #5049

Merged
merged 1 commit into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
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
132 changes: 68 additions & 64 deletions tests/integration/adapter/build-url-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {module, test} from 'qunit';

import DS from 'ember-data';

var env, store, adapter, Post, Comment, SuperUser;
var passedUrl;
var run = Ember.run;
let env, store, adapter, Post, Comment, SuperUser;
let passedUrl;
const { run } = Ember;

module("integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter", {
beforeEach() {
Expand Down Expand Up @@ -58,7 +58,7 @@ function ajaxResponse(value) {


test('buildURL - with host and namespace', function(assert) {
run(function() {
run(() => {
adapter.setProperties({
host: 'http://example.com',
namespace: 'api/v1'
Expand All @@ -67,33 +67,34 @@ test('buildURL - with host and namespace', function(assert) {

ajaxResponse({ posts: [{ id: 1 }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
return run(store, 'findRecord', 'post', 1).then(post => {
assert.equal(passedUrl, "http://example.com/api/v1/posts/1");
}));
});
});

test('buildURL - with relative paths in links', function(assert) {
run(function() {
run(() => {
adapter.setProperties({
host: 'http://example.com',
namespace: 'api/v1'
});
});

Post.reopen({ comments: DS.hasMany('comment', { async: true }) });
Comment.reopen({ post: DS.belongsTo('post', { async: false }) });

ajaxResponse({ posts: [{ id: 1, links: { comments: 'comments' } }] });

run(store, 'findRecord', 'post', '1').then(assert.wait(function(post) {
return run(store, 'findRecord', 'post', '1').then(post => {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
}).then(comments => {
assert.equal(passedUrl, "http://example.com/api/v1/posts/1/comments");
}));
});
});

test('buildURL - with absolute paths in links', function(assert) {
run(function() {
run(() => {
adapter.setProperties({
host: 'http://example.com',
namespace: 'api/v1'
Expand All @@ -104,17 +105,17 @@ test('buildURL - with absolute paths in links', function(assert) {

ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
return run(store, 'findRecord', 'post', 1).then(post => {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
}).then(comments => {
assert.equal(passedUrl, "http://example.com/api/v1/posts/1/comments");
}));
});
});


test('buildURL - with absolute paths in links and protocol relative host', function(assert) {
run(function() {
run(() => {
adapter.setProperties({
host: '//example.com',
namespace: 'api/v1'
Expand All @@ -125,16 +126,16 @@ test('buildURL - with absolute paths in links and protocol relative host', funct

ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
return run(store, 'findRecord', 'post', 1).then(post => {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
}).then(comments => {
assert.equal(passedUrl, "//example.com/api/v1/posts/1/comments");
}));
});
});

test('buildURL - with absolute paths in links and host is /', function(assert) {
run(function() {
run(() => {
adapter.setProperties({
host: '/',
namespace: 'api/v1'
Expand All @@ -145,12 +146,12 @@ test('buildURL - with absolute paths in links and host is /', function(assert) {

ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
return run(store, 'findRecord', 'post', 1).then(post => {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
}).then(comments => {
assert.equal(passedUrl, '/api/v1/posts/1/comments', 'host stripped out properly');
}));
});
});

test('buildURL - with full URLs in links', function(assert) {
Expand All @@ -169,30 +170,30 @@ test('buildURL - with full URLs in links', function(assert) {
]
});

run(function() {
store.findRecord('post', 1).then(assert.wait(function(post) {
return run(() => {
return store.findRecord('post', 1).then(post => {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
}).then(comments => {
assert.equal(passedUrl, "http://example.com/api/v1/posts/1/comments");
}));
});
});
});

test('buildURL - with camelized names', function(assert) {
adapter.setProperties({
pathForType(type) {
var decamelized = Ember.String.decamelize(type);
let decamelized = Ember.String.decamelize(type);
return Ember.String.underscore(Ember.String.pluralize(decamelized));
}
});

ajaxResponse({ superUsers: [{ id: 1 }] });

run(function() {
store.findRecord('super-user', 1).then(assert.wait(function(post) {
return run(() => {
return store.findRecord('super-user', 1).then(post => {
assert.equal(passedUrl, "/super_users/1");
}));
});
});
});

Expand All @@ -204,8 +205,8 @@ test('buildURL - buildURL takes a record from find', function(assert) {

ajaxResponse({ comments: [{ id: 1 }] });

var post;
run(function() {
let post;
run(() => {
post = store.push({
data: {
type: 'post',
Expand All @@ -214,10 +215,10 @@ test('buildURL - buildURL takes a record from find', function(assert) {
});
});

run(function() {
store.findRecord('comment', 1, { preload: { post: post } }).then(assert.wait(function(post) {
return run(() => {
return store.findRecord('comment', 1, { preload: { post: post } }).then(post => {
assert.equal(passedUrl, "/posts/2/comments/1");
}));
});
});
});

Expand All @@ -234,9 +235,9 @@ test('buildURL - buildURL takes the records from findMany', function(assert) {
adapter.coalesceFindRequests = true;

ajaxResponse({ comments: [{ id: 1 }, { id: 2 }, { id: 3 }] });
var post;
let post;

run(function() {
return run(() => {
post = store.push({
data: {
type: 'post',
Expand All @@ -252,9 +253,10 @@ test('buildURL - buildURL takes the records from findMany', function(assert) {
}
}
});
post.get('comments').then(assert.wait(function(post) {

return post.get('comments').then(post => {
assert.equal(passedUrl, "/posts/2/comments/");
}));
});
});
});

Expand All @@ -266,18 +268,18 @@ test('buildURL - buildURL takes a record from create', function(assert) {

ajaxResponse({ comments: [{ id: 1 }] });

run(function() {
var post = store.push({
return run(() => {
let post = store.push({
data: {
type: 'post',
id: '2'
}
});
var comment = store.createRecord('comment');
let comment = store.createRecord('comment');
comment.set('post', post);
comment.save().then(assert.wait(function(post) {
return comment.save().then(post => {
assert.equal(passedUrl, "/posts/2/comments/");
}));
});
});
});

Expand All @@ -286,8 +288,8 @@ test('buildURL - buildURL takes a record from create to query a resolved async b

ajaxResponse({ posts: [{ id: 2 }] });

run(function() {
store.findRecord('post', 2).then(assert.wait(function(post) {
return run(() => {
store.findRecord('post', 2).then(post => {
assert.equal(post.get('id'), 2);

adapter.buildURL = function(type, id, snapshot) {
Expand All @@ -296,13 +298,12 @@ test('buildURL - buildURL takes a record from create to query a resolved async b

ajaxResponse({ comments: [{ id: 1 }] });

var comment = store.createRecord('comment');
let comment = store.createRecord('comment');
comment.set('post', post);
comment.save().then(assert.wait(function(post) {
return comment.save().then(post => {
assert.equal(passedUrl, "/posts/2/comments/");
}));

}));
});
});
});
});

Expand All @@ -314,8 +315,8 @@ test('buildURL - buildURL takes a record from update', function(assert) {

ajaxResponse({ comments: [{ id: 1 }] });

var post, comment;
run(function() {
let post, comment;
run(() => {
post = store.push({
data: {
type: 'post',
Expand All @@ -330,10 +331,11 @@ test('buildURL - buildURL takes a record from update', function(assert) {
});
comment.set('post', post);
});
run(function() {
comment.save().then(assert.wait(function(post) {

return run(() => {
return comment.save().then(post => {
assert.equal(passedUrl, "/posts/2/comments/1");
}));
});
});
});

Expand All @@ -346,8 +348,9 @@ test('buildURL - buildURL takes a record from delete', function(assert) {

ajaxResponse({ comments: [{ id: 1 }] });

var post, comment;
run(function() {
let post, comment;

run(() => {
post = store.push({
data: {
type: 'post',
Expand All @@ -364,23 +367,24 @@ test('buildURL - buildURL takes a record from delete', function(assert) {
comment.set('post', post);
comment.deleteRecord();
});
run(function() {
comment.save().then(assert.wait(function(post) {

return run(() => {
return comment.save().then(post => {
assert.equal(passedUrl, "posts/2/comments/1");
}));
});
});
});

test('buildURL - with absolute namespace', function(assert) {
run(function() {
run(() => {
adapter.setProperties({
namespace: '/api/v1'
});
});

ajaxResponse({ posts: [{ id: 1 }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
return run(store, 'findRecord', 'post', 1).then(post => {
assert.equal(passedUrl, "/api/v1/posts/1");
}));
});
});
Loading