Skip to content

Commit

Permalink
Change setupStore helper default serializer to JSONAPISerializer embe…
Browse files Browse the repository at this point in the history
…rjs#4754 (emberjs#5003)

* Change setupStore helper default serializer to JSONAPISerializer emberjs#4754

* Update test per review feedback
  • Loading branch information
eshtadc authored and sudowork committed Jun 20, 2017
1 parent eee9f17 commit 2da4066
Show file tree
Hide file tree
Showing 36 changed files with 1,093 additions and 482 deletions.
5 changes: 2 additions & 3 deletions tests/helpers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ export default function setupStore(options) {
registry.optionsForType('adapter', { singleton: false });
registry.register('adapter:-default', DS.Adapter);

registry.register('serializer:-default', DS.JSONSerializer);
registry.register('serializer:-default', DS.JSONAPISerializer);
registry.register('serializer:-json', DS.JSONSerializer);
registry.register('serializer:-rest', DS.RESTSerializer);

registry.register('adapter:-rest', DS.RESTAdapter);

registry.register('adapter:-json-api', DS.JSONAPIAdapter);
registry.register('serializer:-json-api', DS.JSONAPISerializer);

env.restSerializer = container.lookup('serializer:-rest');
env.store = container.lookup('service:store');
Expand Down
20 changes: 16 additions & 4 deletions tests/integration/adapter/find-all-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ test("When all records for a type are requested, the store should call the adapt
// this will get called twice
assert.ok(true, "the adapter's findAll method should be invoked");

return resolve([{ id: 1, name: "Braaaahm Dale" }]);
return resolve({ data: [{
id: 1,
type: 'person',
attributes: {
name: "Braaaahm Dale"
}
}]});
}
}));

Expand Down Expand Up @@ -75,7 +81,13 @@ test("When all records for a type are requested, a rejection should reject the p
if (count++ === 0) {
return reject();
} else {
return resolve([{ id: 1, name: "Braaaahm Dale" }]);
return resolve({ data: [{
id: 1,
type: 'person',
attributes: {
name: "Braaaahm Dale"
}
}]});
}
}
}));
Expand Down Expand Up @@ -185,7 +197,7 @@ test("isUpdating is true while records are fetched", function(assert) {

assert.equal(persons.get("isUpdating"), true);

findAllDeferred.resolve([{ id: 2 }]);
findAllDeferred.resolve({ data: [{ id: 2, type: 'person' }] });
});

test("isUpdating is true while records are fetched in the background", function(assert) {
Expand Down Expand Up @@ -223,7 +235,7 @@ test("isUpdating is true while records are fetched in the background", function(
assert.equal(persons.get("isUpdating"), true);

run(function() {
findAllDeferred.resolve([{ id: 2 }]);
findAllDeferred.resolve({ data: [{ id: 2, type: 'person' }] });
});

run(function() {
Expand Down
29 changes: 26 additions & 3 deletions tests/integration/adapter/find-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ test("When a single record is requested, the adapter's find method should be cal
assert.equal(count, 0, "the find method is only called once");

count++;
return { id: 1, name: "Braaaahm Dale" };
return {
data: {
id: 1,
type: "person",
attributes: {
name: "Braaaahm Dale"
}
}
};
}
}));

Expand Down Expand Up @@ -101,7 +109,14 @@ test("When a single record is requested multiple times, all .findRecord() calls
}));
});

run(() => deferred.resolve({ id: 1, name: "Braaaahm Dale" }));
run(() => deferred.resolve({
data: {
id: 1,
type: "person",
attributes: {
name: "Braaaahm Dale"
}
}}));
});

test("When a single record is requested, and the promise is rejected, .findRecord() is rejected.", (assert) => {
Expand Down Expand Up @@ -158,7 +173,15 @@ testInDebug('When multiple records are requested, and the payload is blank', (as
testInDebug("warns when returned record has different id", function(assert) {
env.registry.register('adapter:person', DS.Adapter.extend({
findRecord() {
return { id: 1, name: "Braaaahm Dale" };
return {
data: {
id: 1,
type: "person",
attributes: {
name: "Braaaahm Dale"
}
}
};
}
}));

Expand Down
27 changes: 22 additions & 5 deletions tests/integration/adapter/queries-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,25 @@ test("When a query is made, the adapter should receive a record array it can pop
adapter.query = function(store, type, query, recordArray) {
assert.equal(type, Person, "the query method is called with the correct type");

return Ember.RSVP.resolve([{ id: 1, name: "Peter Wagenet" }, { id: 2, name: "Brohuda Katz" }]);
};
return Ember.RSVP.resolve({
data: [
{
id: 1,
type: 'person',
attributes: {
name: "Peter Wagenet"
}
},
{
id: 2,
type: "person",
attributes: {
name: "Brohuda Katz"
}
}
]
});
}

store.query('person', { page: 1 }).then(assert.wait(function(queryResults) {
assert.equal(get(queryResults, 'length'), 2, "the record array has a length of 2 after the results are loaded");
Expand All @@ -59,7 +76,7 @@ test("When a query is made, the adapter should receive a record array it can pop

test("a query can be updated via `update()`", function(assert) {
adapter.query = function() {
return Ember.RSVP.resolve([{ id: 'first' }]);
return Ember.RSVP.resolve({ data: [{ id: 'first', type: 'person' }] });
};

run(function() {
Expand All @@ -70,7 +87,7 @@ test("a query can be updated via `update()`", function(assert) {

adapter.query = function() {
assert.ok('query is called a second time');
return Ember.RSVP.resolve([{ id: 'second' }]);
return Ember.RSVP.resolve({data: [{ id: 'second', type: 'person' }] });
};

let updateQuery = query.update();
Expand All @@ -96,7 +113,7 @@ testInDebug("The store asserts when query is made and the adapter responses with
adapter.query = function(store, type, query, recordArray) {
assert.equal(type, Person, "the query method is called with the correct type");

return Ember.RSVP.resolve({ people: { id: 1, name: "Peter Wagenet" } });
return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Peter Wagenet" } }] });
};

assert.expectAssertion(function() {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/adapter/record-persistence-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test("When a store is committed, the adapter's `commit` method should be called
assert.equal(type, Person, "the type is correct");
assert.equal(snapshot.record, tom, "the record is correct");

return Ember.RSVP.resolve({ id: 1, name: "Tom Dale" });
return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale" } } });
};

run(function() {
Expand All @@ -92,7 +92,7 @@ test("After a created record has been assigned an ID, finding a record by that I
var tom;

env.adapter.createRecord = function(store, type, snapshot) {
return Ember.RSVP.resolve({ id: 1, name: "Tom Dale" });
return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale" } } });
};

run(function() {
Expand Down Expand Up @@ -178,9 +178,9 @@ test("An adapter can notify the store that records were updated by calling `didS
test("An adapter can notify the store that records were updated and provide new data by calling `didSaveRecords`.", function(assert) {
env.adapter.updateRecord = function(store, type, snapshot) {
if (snapshot.id === "1") {
return Ember.RSVP.resolve({ id: 1, name: "Tom Dale", updatedAt: "now" });
return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } });
} else if (snapshot.id === "2") {
return Ember.RSVP.resolve({ id: 2, name: "Yehuda Katz", updatedAt: "now!" });
return Ember.RSVP.resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } });
}
};

Expand Down Expand Up @@ -249,9 +249,9 @@ test("An adapter can notify the store that a record was updated and provide new
env.adapter.updateRecord = function(store, type, snapshot) {
switch (snapshot.id) {
case "1":
return Ember.RSVP.resolve({ id: 1, name: "Tom Dale", updatedAt: "now" });
return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } });
case "2":
return Ember.RSVP.resolve({ id: 2, name: "Yehuda Katz", updatedAt: "now!" });
return Ember.RSVP.resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } });
}
};

Expand Down
Loading

0 comments on commit 2da4066

Please sign in to comment.