Skip to content

Commit e9aefdb

Browse files
committed
Add addActions test
1 parent 86572ef commit e9aefdb

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

fetch/karma.start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ before(function () {
1515
Test.sinon = sinon
1616
Test.JSData = JSData
1717
Test.addAction = JSDataHttp.addAction
18+
Test.addActions = JSDataHttp.addActions
1819
Test.HttpAdapter = JSDataHttp.HttpAdapter
1920
Test.User = new JSData.Mapper({
2021
name: 'user'

karma.start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ before(function () {
1515
Test.sinon = sinon
1616
Test.JSData = JSData
1717
Test.addAction = JSDataHttp.addAction
18+
Test.addActions = JSDataHttp.addActions
1819
Test.HttpAdapter = JSDataHttp.HttpAdapter
1920
Test.User = new JSData.Mapper({
2021
name: 'user'

node/mocha.start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ before(function () {
1919
Test.sinon = require('sinon')
2020
Test.JSData = require('js-data')
2121
Test.addAction = require('./dist/js-data-http-node').addAction
22+
Test.addActions = require('./dist/js-data-http-node').addActions
2223
Test.HttpAdapter = require('./dist/js-data-http-node').HttpAdapter
2324
Test.User = new Test.JSData.Mapper({
2425
name: 'user'

test/static.addActions.test.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
11
describe('static addActions', function () {
2-
it('should addActions')
2+
it('should addActions', function (done) {
3+
var Test = this
4+
var adapter = Test.adapter
5+
var store = new Test.JSData.DataStore()
6+
store.registerAdapter('http', adapter, { default: true })
7+
var SchoolMapper = store.defineMapper('school', {})
8+
9+
// GET async/reports/schools/:school_id/teachers
10+
Test.addActions({
11+
getTeacherReports: {
12+
endpoint: 'reports/schools',
13+
pathname: 'teachers',
14+
method: 'GET'
15+
},
16+
getStudentReports: {
17+
endpoint: 'reports/schools',
18+
pathname: 'students',
19+
method: 'GET'
20+
}
21+
})(SchoolMapper)
22+
23+
var asyncTestOne = function (nextTest) {
24+
setTimeout(function () {
25+
Test.requests[0].respond(200, { 'Content-Type': 'text/plain' }, '')
26+
}, 5)
27+
28+
SchoolMapper.getTeacherReports(1234).then(function (response) {
29+
Test.assert.equal(1, Test.requests.length)
30+
Test.assert.equal(Test.requests[0].url, 'reports/schools/1234/teachers', 'Add action configures basePath, endpoint and pathname')
31+
Test.assert.equal(Test.requests[0].method, 'GET')
32+
nextTest()
33+
})
34+
}
35+
36+
var asyncTestTwo = function () {
37+
setTimeout(function () {
38+
Test.requests[1].respond(200, { 'Content-Type': 'text/plain' }, '')
39+
}, 5)
40+
41+
SchoolMapper.getStudentReports(1234).then(function (response) {
42+
Test.assert.equal(2, Test.requests.length)
43+
Test.assert.equal(Test.requests[1].url, 'reports/schools/1234/students', 'Add action configures basePath, endpoint and pathname')
44+
Test.assert.equal(Test.requests[1].method, 'GET')
45+
done()
46+
})
47+
}
48+
49+
asyncTestOne(asyncTestTwo)
50+
})
351
})

0 commit comments

Comments
 (0)