Skip to content

Test Coverage (fetch, updateMany/createMany, addAction(s)) #56

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

Merged
merged 6 commits into from
Aug 19, 2016

Conversation

pik
Copy link
Contributor

@pik pik commented Aug 15, 2016

So not all of the top level opts such as basePath per docs are getting merged into _opts in addAction. The following PR should fix it by missing both of them, also adding a test since addAction was missing coverage.

A few other things (maybe worth opening an issue for) - one thing I'm not a huge fan of is the large dynamic function definition in addAction, it may be nicer to have a static function and either bind, or store some of the default arguments to be passed to it.

Another is that addAction is a function in an extension that relies mapper / store introspection to be correct. Would a more general path-way to to allow action: {} definitions in the mapper which the applied / registered adapters be allowed to absorb into their own actions without requiring them to introspect the core framework?

@@ -1064,7 +1064,7 @@ Adapter.extend({
*
* // GET /reports/schools/:school_id/teachers
* addAction('getTeacherReports', {
* basePath: 'reports/schools',
* endppoint: 'reports/schools',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because endpoint is always appended to basePath

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endppoint => endpoint

@pik
Copy link
Contributor Author

pik commented Aug 15, 2016

Another point - should the action return an object if a mapper is specified in options? Currently it's hard for me to tell that there is much advantage to using addAction over declaring a function on the mapper manually e.g.

getTeacherReports(reportId) {
  return adapter.GET(`reports/schools/${reportId}/teachers`)
    .then((response) => {
      /* instantiate a record from response.data*/
    })
},

@jmdobry
Copy link
Member

jmdobry commented Aug 15, 2016

I personally just add my own functions to mappers, but a lot of people clamored for this declarative HTTP action syntax.

 * Adds tests for #action(<id>) and #action(<params>) queries
@@ -18,6 +18,7 @@ before(function () {
}
Test.sinon = require('sinon')
Test.JSData = require('js-data')
Test.addAction = require('./dist/js-data-http-node').addAction
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to de-duplicate these 3 files. I would have preferred to do this via. es6 but I haven't gotten both build pipelines to work correctly with that =/

@codecov-io
Copy link

codecov-io commented Aug 16, 2016

Current coverage is 93.87% (diff: 100%)

Merging #56 into master will increase coverage by 0.54%

@@             master        #56   diff @@
==========================================
  Files             1          1          
  Lines            45         49     +4   
  Methods           7          7          
  Messages          0          0          
  Branches          6          6          
==========================================
+ Hits             42         46     +4   
  Misses            3          3          
  Partials          0          0          

Powered by Codecov. Last update 9d8ca3a...14f7936

@@ -0,0 +1,14 @@
describe('sum', function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure these are worth keeping in the library - but at least added tests for coverage stats.

@pik
Copy link
Contributor Author

pik commented Aug 16, 2016

More tests #36

@pik pik changed the title Fix add-action opts bug + test Test Coverage Aug 17, 2016
try {
fetch // eslint-disable-line
} catch (e) {
return this.skip()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping the mocha test because the fetch polyfill for Node is not actually compatible with the browser fetch. We would need to fork the polyfill or have different fetch behaviors depending on node/browser.

@pik pik changed the title Test Coverage Test Coverage (fetch, updateMany/createMany, addAction(s)) Aug 18, 2016
@@ -18,8 +18,7 @@
"axios",
"rest",
"adapter",
"http",
"fetch"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

@jmdobry jmdobry merged commit 1b7b107 into js-data:master Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants