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

unload should invalidate async hasMany: failing test #5353

Closed
wants to merge 1 commit into from
Closed
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
110 changes: 110 additions & 0 deletions tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,3 +2008,113 @@ test('1 sync : many async unload sync side', function(assert) {
})
);
});

test('unload should invalidate async hasMany', function(assert) {
let isUnloaded = false;
env.adapter.coalesceFindRequests = false;

env.adapter.findRecord = (store, type, id) => {
assert.equal(type, Boat, 'findRecord(_, type) is correct');

if (id === '2' && isUnloaded) {
throw "not found";
}

let relationships = {
person: {
data: {
type: 'person',
id: '1'
}
}
};

return {
data: {
type: 'boat',
id: id,
relationships
}
}
};

env.adapter.findHasMany = (store, snapshot, link) => {
assert.equal(snapshot.modelName, 'person', 'findHasMany(_, snapshot) is correct');
assert.equal(link, 'boats', 'findHasMany(_, _, link) is correct');

let relationships = {
person: {
data: {
type: 'person',
id: 1
}
}
};

let data = [
{
id: 3,
type: 'boat',
relationships
}
];

if (!isUnloaded) {
data.unshift({
id: 2,
type: 'boat',
relationships
});
}

return {
data
};
};

let person = run(() =>
env.store.push({
data: {
id: 1,
type: 'person',
relationships: {
boats: {
links: { related: 'boats' }
// data: [{
// id: 2,
// type: 'boat'
// },{
// id: 3,
// type: 'boat'
// },
// ]
}
}
}
})
);
let boats, boat2, boat3;

return run(() =>
person.get('boats').then((asyncRecords) => {
boats = asyncRecords;
[boat2, boat3] = boats.toArray();
}).then(() => {
assert.deepEqual(person.hasMany('boats').ids(), ['2', '3'], 'initially relationship established rhs');
assert.equal(boat2.belongsTo('person').id(), '1', 'initially relationship established rhs');
assert.equal(boat3.belongsTo('person').id(), '1', 'initially relationship established rhs');

isUnloaded = true;
run(() => boat2.unloadRecord());

assert.deepEqual(boats.mapBy('id'), ['3'], 'unloaded boat is removed from ManyArray');
//NOTE: uncommenting the next line fixes this test
// return person.hasMany('boats').reload();
}).then(() => {
assert.deepEqual(person.hasMany('boats').ids(), ['3'], 'hasMany should also only have 1 left');
return run(() => person.get('boats'));
}).then(newBoats => {
assert.equal(newBoats.length, 1, 'new ManyArray has only 1 boat after unload');
})
);
});