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

[SIDE QUEST] MinimumAdapterInterface Tests #6666

Closed
72 tasks done
runspired opened this issue Nov 4, 2019 · 1 comment
Closed
72 tasks done

[SIDE QUEST] MinimumAdapterInterface Tests #6666

runspired opened this issue Nov 4, 2019 · 1 comment
Labels
🌲 Project Trim 🌲 PRs related to https://github.com/emberjs/data/issues/6166

Comments

@runspired
Copy link
Contributor

runspired commented Nov 4, 2019

A Side-Quest for Project Trim!

Side Quests?!?! How fun!

Mission

#6497 introduced test infrastructure for testing ember-data without the @ember-data/adapter package being present at all while #6643 introduces the MinimumAdapterInterface. In this repository we want to add integration tests covering the minimum APIs.

The following requests should be tested:

Queries

  • store.findRecord calls adapter.findRecord w/correct args

  • store.findAll calls adapter.findAll w/correct args

  • store.query calls adapter.query w/correct args

  • store.queryRecord calls adapter.queryRecord w/correct args

  • if coalesceFindRequests is true

    • if findMany is not defined we call findRecord for each request and do not call groupRecordsForFindMany
    • we call groupRecordsForFindMany with the right args if multiple findRecords are triggered
    • we call findMany with the right args
    • we do not call findRecord
  • if coalesceFindRequests is false or undefined, multiple calls to store.findRecord are not coalesced

  • if a belongsTo relationship has a link but no data

    • if findBelongsTo is defined we call it and not findRecord
    • if findBelongsTo is not defined we throw a clear error
  • if a belongsTo relationship has data but not a link

    • if findBelongsTo is defined we call findRecord not findBelongsTo
    • if findBelongsTo is undefined we still call findRecord not findBelongsTo (no error)
  • if a belongsTo relationship has a link and data

    • if findBelongsTo is defined we call it and not findRecord
    • if findBelongsTo is not defined we call findRecord (no error)
  • if a hasMany relationship has a link but no data

    • if findHasMany is defined we call it and not findRecord OR findMany
    • if findHasMany is not defined we throw a clear error
  • if a hasMany relationship has data but not a link

    • if findHasMany is defined and coalescing is off we call findRecord for each record
    • if findHasMany is defined and coalescing is on we call findMany
    • if findHasMany is undefined and coalescing is off we call findRecord for each record (no error)
    • if findHasMany is undefined and coalescing is on we call findMany (no error)
  • if a hasMany relationship has a link and data

    • if findHasMany is defined we call it and not findRecord or findMany
    • if findHasMany is not defined and coalescing is off we call findRecord for each record (no error)
    • if findHasMany is not defined and coalescing is on we call findMany

Mutations

  • store.deleteRecord calls adapter.deleteRecord if a record is deleted and then saved

  • store.deleteRecord calls adapter.deleteRecord if a newly created record is persisted, then deleted and then saved

  • store.deleteRecord does not call adapter.deleteRecord if a newly created, unpersisted record is deleted and then saved

  • record.save() calls adapter.createRecord if a newly created record unpersisted record is saved

  • record.save() calls adapter.createRecord then adapter.updateRecord if a newly created record record is saved, then saved again

  • record.save() calls adapter.updateRecord if an existing persisted record is saved

Reloading

The reload tests should be in one test file specifically for reloading and each section below should be a nested module within that test file.
I might suggest creating a utility to set the state of the various flags and hooks for each test. While DRY is generally to be avoided, a few well
crafted helpers here would improve the legibility of the combinations of flags, helping us to see the nuances of various combos.

For when these methods are undefined there may be fixes required in the current logic in core-store.ts.

  • adapter.shouldReloadAll (adapter.shouldBackgroundReloadAll should return false for all of these)

    • adapter.shouldReloadAll is not called when store.findAll is called with a reload: false flag (and we do not make a request)
    • adapter.shouldReloadAll is not called when store.findAll is called with a reload: true flag (and we make a request).
    • store.findAll does not error if adapter.shouldReloadAll is not defined
      • if adapter.shouldReloadAll is undefined we default to false if records are present (and we do not make a request)
      • if adapter.shouldReloadAll is undefined we default to true if records are not present (and we make a request)
    • adapter.shouldReloadAll is called when store.findAll is called without a reload flag.
      • if adapter.shouldReloadAll returns true we make a request
      • if adapter.shouldReloadAll returns false we do not make a request
  • adapter.shouldBackgroundReloadAll

    • adapter.shouldBackgroundReloadAll is not called called when store.findAll is called with reload: true flag (but we do make request)
    • adapter.shouldBackgroundReloadAll is not called called when store.findAll is called and shouldReloadAll returns true (but we do make request)
    • When reload: false or no reload flag and adapter.shouldReloadAll returns false
      • adapter.shouldBackgroundReloadAll is not called when store.findAll is called with backroundReload as an option.
        • if backgroundReload is true we make a request
        • if backgroundReload is false we do not make a request
      • store.findAll does not error if adapter.shouldBackgroundReloadAll is undefined and backgroundReload is not present.
        • if adapter.shouldBackgroundReloadAll is undefined we default to true and we make a request
      • adapter.shouldBackgroundReloadAll is called when store.findAll is called and there is no backgroundReload flag
        • if adapter.shouldBackgroundReloadAll returns true we make a request
        • if adapter.shouldBackgroundReloadAll returns false we do not make a request
  • adapter.shouldReloadRecord

    • adapter.shouldReloadRecord is not called when store.findRecord is called for an unloaded record (but we do make request)
    • adapter.shouldReloadRecord is not called when store.findRecord is called for a never loaded record (but we do make request)
    • adapter.shouldReloadRecord is not called when store.findRecord is called with a reload flag (but we do make request if reload is true)
    • adapter.shouldReloadRecord is not called when store.findRecord is called with a reload flag (and we do not make request if reload is false)
    • store.findRecord should not error if adapter.shouldReloadRecord is undefined
      • if adapter.shouldReloadRecord is undefined, we default to false and do not make a request
    • adapter.shouldReloadRecord is called when store.findRecord is called without a reload flag.
      • if adapter.shouldReloadRecord returns true we make a request
      • if adapter.shouldReloadRecord returns false we do not make a request
  • adapter.shouldBackgroundReloadRecord

    • adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called for an unloaded record (but we do make request)
    • adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called for a never loaded record (but we do make request)
    • adapter.shouldBackgroundReloadRecord is not called called when store.findRecord is called with reload: true flag (but we do make request)
    • adapter.shouldBackgroundReloadRecord is not called called when store.findRecord is called and shouldReloadRecord returns true (but we do make request)
    • When reload: false or no reload flag and adapter.shouldReloadRecord returns false
      • adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called with backroundReload as an option.
        • if backgroundReload is true we make a request
        • if backgroundReload is false we do not make a request
      • store.findRecord does not error if adapter.shouldBackgroundReloadRecord is undefined and backgroundReload is not present.
        • if adapter.shouldBackgroundReloadRecord is undefined we default to true and we make a request
      • adapter.shouldBackgroundReloadRecord is called when store.findRecord is called and there is no backgroundReload flag
        • if adapter.shouldBackgroundReloadRecord returns true we make a request
        • if adapter.shouldBackgroundReloadRecord returns false we do not make a request

Other

  • store.createRecord calls adapter.generateIdForRecord if defined and we use this ID for the record
    • we can peekRecord a newly created record for which we generated an ID in the adapter
  • store.createRecord does not error if adapter.generateIdForRecord is undefined.
@runspired
Copy link
Contributor Author

#6824 completes this quest, thank you again @Gaurav0 !

@runspired runspired unpinned this issue Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌲 Project Trim 🌲 PRs related to https://github.com/emberjs/data/issues/6166
Projects
None yet
Development

No branches or pull requests

1 participant