-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Coverage (fetch, updateMany/createMany, addAction(s)) (#56)
* Fix addAction to pass through opts into _opts on functional call * Adds tests for #action(<id>) and #action(<params>) queries * Add addActions test * Setup store and adapter in start.js * Sum and count tests * Tests for createMany and updateMany * Add fetch test
- Loading branch information
Showing
15 changed files
with
247 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,7 @@ | |
"axios", | ||
"rest", | ||
"adapter", | ||
"http", | ||
"fetch" | ||
"http" | ||
], | ||
"dependencies": { | ||
"js-data-adapter": "~0.8.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
describe('sum', function () { | ||
it('should include count=true in query_params', function (done) { | ||
var Test = this | ||
|
||
setTimeout(function () { | ||
Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{"count": 5}') | ||
}, 5) | ||
|
||
Test.adapter.count(Test.Post).then(function (result) { | ||
Test.assert.equal(Test.requests[0].url, 'api/posts?count=true') | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
describe('createMany', function () { | ||
it('should createMany') | ||
it('should createMany', function (done) { | ||
var Test = this | ||
|
||
setTimeout(function () { | ||
Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, '') | ||
}, 5) | ||
|
||
var many = [{ author_id: 2, text: 'bar' }, { author_id: 2, text: 'foo' }] | ||
Test.Post.createMany(many).then(function (result) { | ||
Test.assert.equal(Test.requests[0].url, 'api/posts') | ||
Test.assert.equal(Test.requests[0].method, 'POST') | ||
Test.assert.equal(Test.requests[0].requestBody, JSON.stringify(many)) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
describe('fetch', function () { | ||
it('should fetch') | ||
it('should fetch from a URL', function (done) { | ||
var Test = this | ||
// Don't test fetch for Node | ||
try { | ||
fetch // eslint-disable-line | ||
} catch (e) { | ||
return this.skip() | ||
} | ||
if (Test.TEST_FETCH) { | ||
Test.xhr = Test.sinon.useFakeXMLHttpRequest() | ||
Test.requests = [] | ||
Test.xhr.onCreate = function (xhr) { | ||
Test.requests.push(xhr) | ||
} | ||
} | ||
|
||
setTimeout(function () { | ||
Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{}') | ||
}, 300) | ||
|
||
Test.adapter.fetch({ | ||
method: 'get', | ||
params: { active: true }, | ||
url: '/api/foos' | ||
}).then(function (response) { | ||
var request = Test.requests[0] | ||
Test.assert.equal(request.method, 'GET') | ||
Test.assert.equal(request.url, '/api/foos?active=true') | ||
if (Test.TEST_FETCH) { | ||
Test.xhr.restore() | ||
} | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
describe('static addAction', function () { | ||
it('should addAction') | ||
it('should addAction', function (done) { | ||
var Test = this | ||
var SchoolMapper = Test.store.defineMapper('school', {}) | ||
|
||
// GET async/reports/schools/:school_id/teachers | ||
Test.addAction('getTeacherReportsAsync', { | ||
basePath: 'async/', | ||
endpoint: 'reports/schools', | ||
pathname: 'teachers', | ||
method: 'GET' | ||
})(SchoolMapper) | ||
|
||
setTimeout(function () { | ||
Test.requests[0].respond(200, { 'Content-Type': 'text/plain' }, '') | ||
}, 5) | ||
|
||
SchoolMapper.getTeacherReportsAsync(1234).then(function (response) { | ||
Test.assert.equal(1, Test.requests.length) | ||
Test.assert.equal(Test.requests[0].url, 'async/reports/schools/1234/teachers', 'Add action configures basePath, endpoint and pathname') | ||
Test.assert.equal(Test.requests[0].method, 'GET') | ||
done() | ||
}) | ||
}) | ||
|
||
it('addAction action is callable with params instead of id', function (done) { | ||
var Test = this | ||
var adapter = Test.adapter | ||
var store = new Test.JSData.DataStore() | ||
store.registerAdapter('http', adapter, { default: true }) | ||
var SchoolMapper = store.defineMapper('school', {}) | ||
|
||
// GET async/reports/schools/teachers | ||
Test.addAction('getAllTeacherReportsAsync', { | ||
basePath: 'async/', | ||
endpoint: 'reports/schools', | ||
pathname: 'teachers', | ||
method: 'GET' | ||
})(SchoolMapper) | ||
|
||
setTimeout(function () { | ||
Test.requests[0].respond(200, { 'Content-Type': 'text/plain' }, '') | ||
}, 5) | ||
|
||
// GET async/reports/schools/teachers?<key>=<value> | ||
SchoolMapper.getAllTeacherReportsAsync({ | ||
params: { | ||
subject: 'esperanto' | ||
} | ||
}).then(function (response) { | ||
Test.assert.equal(1, Test.requests.length) | ||
Test.assert.equal(Test.requests[0].url, 'async/reports/schools/teachers?subject=esperanto', 'Add action configures basePath, endpoint, pathname, and querystring') | ||
Test.assert.equal(Test.requests[0].method, 'GET') | ||
done() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.