Skip to content

Commit a1c198f

Browse files
committed
Initial release
0 parents  commit a1c198f

12 files changed

+670
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
*.log

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
##### 1.0.0 - 09 November 2015
2+
3+
- Initial release

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="64" height="64" />
2+
3+
## js-data-adapter-tests [![Slack Status][sl_b]][sl_l] [![npm version][npm_b]][npm_l] [![Circle CI][circle_b]][circle_l] [![npm downloads][dn_b]][dn_l]
4+
5+
Tests for [js-data](http://www.js-data.io/) adapters.
6+
7+
See [js-data-sql](https://github.com/js-data/js-data-adapter-tests/blob/master/mocha.start.js) for usage.
8+
9+
### Changelog
10+
[CHANGELOG.md](https://github.com/js-data/js-data-adapter-tests/blob/master/CHANGELOG.md)
11+
12+
### Community
13+
- [Slack Channel](http://slack.js-data.io) - Better than IRC!
14+
15+
### License
16+
17+
The MIT License (MIT)
18+
19+
Copyright (c) 2014-2015 Jason Dobry
20+
21+
Permission is hereby granted, free of charge, to any person obtaining a copy
22+
of this software and associated documentation files (the "Software"), to deal
23+
in the Software without restriction, including without limitation the rights
24+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
copies of the Software, and to permit persons to whom the Software is
26+
furnished to do so, subject to the following conditions:
27+
28+
The above copyright notice and this permission notice shall be included in all
29+
copies or substantial portions of the Software.
30+
31+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37+
SOFTWARE.
38+
39+
[sl_b]: http://slack.js-data.io/badge.svg
40+
[sl_l]: http://slack.js-data.io
41+
[npm_b]: https://img.shields.io/npm/v/js-data-adapter-tests.svg?style=flat
42+
[npm_l]: https://www.npmjs.org/package/js-data-adapter-tests
43+
[circle_b]: https://img.shields.io/circleci/project/js-data/js-data-adapter-tests/master.svg?style=flat
44+
[circle_l]: https://circleci.com/gh/js-data/js-data-adapter-tests/tree/master
45+
[dn_b]: https://img.shields.io/npm/dm/js-data-adapter-tests.svg?style=flat
46+
[dn_l]: https://www.npmjs.org/package/js-data-adapter-tests

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "js-data-adapter-tests",
3+
"description": "Tests for js-data adapters.",
4+
"version": "1.0.0",
5+
"homepage": "http://www.js-data.io",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/js-data/js-data-adapter-tests.git"
9+
},
10+
"author": {
11+
"name": "Jason Dobry",
12+
"url": "http://www.pseudobry.com",
13+
"email": "jason.dobry@gmail.com"
14+
},
15+
"license": "MIT",
16+
"main": "./src/index.js",
17+
"keywords": [
18+
"js-data",
19+
"adapter",
20+
"test"
21+
],
22+
"devDependencies": {
23+
"babel-eslint": "4.1.3",
24+
"standard": "5.3.1"
25+
},
26+
"standard": {
27+
"parser": "babel-eslint",
28+
"globals": [
29+
"describe",
30+
"it",
31+
"before",
32+
"after",
33+
"beforeEach",
34+
"afterEach",
35+
"assert"
36+
]
37+
},
38+
"scripts": {
39+
"lint": "standard src/**/*.js",
40+
"test": "npm run lint"
41+
},
42+
"peerDependencies": {
43+
"chai": "~3.x"
44+
}
45+
}

src/create.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = function (adapter) {
2+
describe('Adapter#create', function () {
3+
it('should exist', function * () {
4+
assert.equal(typeof this.$$adapter.create, 'function', 'adapter should have a "create" method')
5+
})
6+
it('should create a user', function * () {
7+
var adapter = this.$$adapter
8+
var User = this.$$User
9+
var createUser = yield adapter.create(User, {name: 'John'})
10+
var id = createUser.id
11+
assert.equal(createUser.name, 'John')
12+
assert.isDefined(createUser.id)
13+
14+
var findUser = yield adapter.find(User, createUser.id)
15+
assert.equal(findUser.name, 'John')
16+
assert.isDefined(findUser.id)
17+
assert.equalObjects(findUser, {id: id, name: 'John', age: null, profileId: null})
18+
19+
var destoryUser = yield adapter.destroy(User, findUser.id)
20+
assert.isFalse(!!destoryUser)
21+
22+
try {
23+
yield adapter.find(User, id)
24+
throw new Error('Should not have reached here!')
25+
} catch (err) {
26+
assert.equal(err.message, 'Not Found!')
27+
}
28+
})
29+
})
30+
}

src/destroy.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = function (adapter) {
2+
describe('Adapter#destroy', function () {
3+
it('should exist', function * () {
4+
assert.equal(typeof this.$$adapter.destroy, 'function', 'adapter should have a "destroy" method')
5+
})
6+
it('should destroy a user', function * () {
7+
var adapter = this.$$adapter
8+
var User = this.$$User
9+
var createUser = yield adapter.create(User, {name: 'John'})
10+
var id = createUser.id
11+
12+
var destroyUser = yield adapter.destroy(User, createUser.id)
13+
assert.isFalse(!!destroyUser)
14+
15+
try {
16+
yield adapter.find(User, id)
17+
throw new Error('Should not have reached here!')
18+
} catch (err) {
19+
assert.equal(err.message, 'Not Found!')
20+
}
21+
})
22+
})
23+
}

src/destroyAll.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = function (adapter) {
2+
describe('Adapter#destroyAll', function () {
3+
it('should exist', function * () {
4+
assert.equal(typeof this.$$adapter.destroyAll, 'function', 'adapter should have a "destroyAll" method')
5+
})
6+
it('should destroy all users', function * () {
7+
var adapter = this.$$adapter
8+
var User = this.$$User
9+
var createUser = yield adapter.create(User, {name: 'John'})
10+
var id = createUser.id
11+
12+
var findUsers = yield adapter.findAll(User, { name: 'John' })
13+
assert.equal(findUsers.length, 1)
14+
assert.equalObjects(findUsers[0], {id: id, name: 'John', age: null, profileId: null})
15+
16+
yield adapter.destroyAll(User, { name: 'John' })
17+
var findUsers2 = yield adapter.findAll(User, { name: 'John' })
18+
assert.equal(findUsers2.length, 0)
19+
})
20+
})
21+
}

src/find.test.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
module.exports = function (adapter) {
2+
describe('Adapter#find', function () {
3+
var adapter, User, Profile, Post, Comment
4+
5+
beforeEach(function () {
6+
adapter = this.$$adapter
7+
User = this.$$User
8+
Profile = this.$$Profile
9+
Post = this.$$Post
10+
Comment = this.$$Comment
11+
})
12+
13+
it('should exist', function * () {
14+
assert.equal(typeof adapter.find, 'function', 'adapter should have a "find" method')
15+
})
16+
17+
it('should find a user', function * () {
18+
var user = yield adapter.create(User, {name: 'John'})
19+
var userId = user.id
20+
assert.equal(user.name, 'John')
21+
assert.isDefined(user.id)
22+
23+
var user2 = yield adapter.find(User, user.id)
24+
assert.equal(user2.name, 'John')
25+
assert.isDefined(user2.id)
26+
assert.equalObjects(user2, {id: userId, name: 'John', age: null, profileId: null})
27+
28+
var post = yield adapter.create(Post, { content: 'test', userId: userId })
29+
var postId = post.id
30+
assert.equal(post.content, 'test')
31+
assert.isDefined(post.id)
32+
assert.isDefined(post.userId)
33+
34+
var comments = yield [
35+
adapter.create(Comment, {
36+
content: 'test2',
37+
postId: post.id,
38+
userId: user.id
39+
}),
40+
adapter.create(Comment, {
41+
content: 'test3',
42+
postId: post.id,
43+
userId: user.id
44+
})
45+
]
46+
47+
comments.sort(function (a, b) {
48+
return a.content > b.content
49+
})
50+
51+
var findPost = yield adapter.find(Post, postId, {with: ['user', 'comment']})
52+
findPost.comments.sort(function (a, b) {
53+
return a.content > b.content
54+
})
55+
assert.equalObjects(findPost.user, user)
56+
assert.equalObjects(findPost.comments, comments)
57+
58+
yield adapter.destroyAll(Comment)
59+
yield adapter.destroy(Post, postId)
60+
var destroyUser = yield adapter.destroy(User, userId)
61+
assert.isFalse(!!destroyUser)
62+
63+
try {
64+
yield adapter.find(User, userId)
65+
throw new Error('Should not have reached here!')
66+
} catch (err) {
67+
assert.equal(err.message, 'Not Found!')
68+
}
69+
})
70+
71+
it('should load belongsTo relations', function * () {
72+
var profile = yield adapter.create(Profile, { email: 'foo@test.com' })
73+
var user = yield adapter.create(User, {name: 'John', profileId: profile.id})
74+
var post = yield adapter.create(Post, {content: 'foo', userId: user.id})
75+
var comment = yield adapter.create(Comment, { content: 'test2', postId: post.id, userId: post.userId })
76+
77+
comment = yield adapter.find(Comment, comment.id, {'with': ['user', 'user.profile', 'post', 'post.user']})
78+
assert.isDefined(comment)
79+
assert.isDefined(comment.post)
80+
assert.isDefined(comment.post.user)
81+
assert.isDefined(comment.user)
82+
assert.isDefined(comment.user.profile)
83+
})
84+
85+
it('should load hasMany and belongsTo relations', function * () {
86+
var profile = yield adapter.create(Profile, { email: 'foo@test.com' })
87+
var user = yield adapter.create(User, {name: 'John', profileId: profile.id})
88+
var post = yield adapter.create(Post, {content: 'foo', userId: user.id})
89+
yield adapter.create(Comment, { content: 'test2', postId: post.id, userId: post.userId })
90+
91+
var foundPost = yield adapter.find(Post, post.id, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']})
92+
assert.isDefined(foundPost.comments)
93+
assert.isDefined(foundPost.comments[0].user)
94+
assert.isDefined(foundPost.comments[0].user.profile)
95+
assert.isDefined(foundPost.user)
96+
})
97+
})
98+
}

0 commit comments

Comments
 (0)