Skip to content

Commit

Permalink
simpler test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 21, 2021
1 parent f038639 commit 010804a
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@ module('Integration | Graph | Nodes', function(hooks) {
*
* Ergo we expect no entries removed (`removed: false`) and for no caches
* to have been deleted (`cleared: false`)
*
* However: for a newly created record any form of rollback, unload or persisted delete
* will result in it being destroyed and cleared
*/
await testFinalState(this, testState, config, { removed: false, cleared: false }, assert);
await testFinalState(
this,
testState,
config,
{ removed: !!config.useCreate, cleared: !!config.useCreate, implicitCleared: !!config.useCreate },
assert
);
});
}

Expand Down Expand Up @@ -124,33 +133,34 @@ module('Integration | Graph | Nodes', function(hooks) {
await settled();

/**
* For unload, we treat it as a deletion for sync relationships and
* For unload, we treat it as a persisted deletion for new records and for sync relationships and
* as no-change for async relationships.
*
* Ergo for async we expect no entries removed (`removed: false`) and for no caches
* to have been deleted (`cleared: false`)
*
* And for sync we expect entries removed (`removed: true`) but for no caches to have been
* deleted. (`cleared: false`)
*
* HOWEVER: for async/sync implicit (`inverseNull`) we expect relationships to be removed but not cleared
* AND for async implicit hasMany relationships we expect the relationships to be cleared as well.
* For local-changes of implicit hasMany relationships we expect the relationships to be cleared as well,
* this special case is handled within ./helpers.ts and is something we can ideally delete as a behavior
* in the future.
*
* FURTHER: for newly created records we expect the inverse to be cleaned up (chris) but for the relationships
* For newly created records we expect the inverse to be cleaned up (chris) but for the relationships
* for the newly created record to be fully intact. There's no particularly good reason for this other than
* we've counted on the record's destroyed state removing these objects from the graph. The inverse relationship
* state containers will have removed any retained info about the newly created record.
*
* Finally, we expect that even though the relationships on `john` could have been removed in the `sync` case
* that they won't be removed in either case from local and only if from remote if dirtyLocal or useCreate is true.
* The relationships in this case will still be removed from chris. We are possibly retaining these relationships
* despite transitioning the record to an `empty` state in the off chance we need to rematerialize the record.
* Likely for most cases this is just a bug.
*
* If this is confusing that's exactly why we've now added this test suite. People depend on this weirdly
* observable behavior, so we want to know when it changes.
*/
await testFinalState(
this,
testState,
config,
{ removed: config.useCreate ? true : !_config.async, cleared: !_config.async && !config.inverseNull },
assert
);

// we remove if the record was new or if the relationship was sync (client side delete semantics)
let removed = config.useCreate || !config.async;
// we clear sync non-implicit relationships (client side delete semantics)
let cleared = !config.async && !config.inverseNull;

await testFinalState(this, testState, config, { removed, cleared, implicitCleared: true }, assert);
});
}

Expand Down Expand Up @@ -181,20 +191,22 @@ module('Integration | Graph | Nodes', function(hooks) {
* For persisted deletions, we expect the cache to have removed all entries for
* the deleted record from both explicit and implicit inverses.
*
* Ergo we expect entries removed (`removed: true`) and for no caches
* to have been deleted (`cleared: false`)
* Ergo we expect entries removed (`removed: true`) and for all caches
* to have been deleted (`cleared: true`)
*
* For unclear reasons, currently async hasMany relationships are emptied
* but not cleared prior to dematerialization after a persisted delete.
* For unclear reasons, currently sync hasMany relationships are emptied
* but not cleared prior to dematerialization after a persisted delete
* only when there is dirty local state. (`cleared: false`) while the
* implicit caches are still cleared.
*
* This could be either an intentional or unintentional bug caused by the need
* to be able to sometimes resurrect a many array during unload.
*/
let cleared = true;
if (config.relType === 'hasMany' && !config.async) {
if (config.relType === 'hasMany' && !config.async && config.dirtyLocal) {
cleared = false;
}
await testFinalState(this, testState, config, { removed: true, cleared }, assert);
await testFinalState(this, testState, config, { removed: true, cleared, implicitCleared: true }, assert);
});
}

Expand Down
Loading

0 comments on commit 010804a

Please sign in to comment.