Skip to content

Commit fc66658

Browse files
committed
added jasmine tests for user
1 parent 84ebec4 commit fc66658

File tree

4 files changed

+127
-310
lines changed

4 files changed

+127
-310
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "node-kc",
2+
"name": "node-kc-stalkqr",
33
"version": "0.0.1",
44
"dependencies": {
55
"express": "~v2.5.6",
66
"coffee-script": "~v1.2.0",
7-
"clone", "v0.0.4",
7+
"clone": "v0.0.4",
88
"jade": "~v0.20.0",
99
"stylus": "~v0.22.5",
1010
"passport": "~v0.1.6",
@@ -14,10 +14,11 @@
1414

1515
"devDependencies": {
1616
"vows": "~v0.6.1",
17-
"should": "~v0.5.1"
17+
"should": "~v0.5.1",
18+
"jasmine-node": "v1.0.21"
1819
},
1920

2021
"scripts": {
21-
"test": "vows --spec"
22+
"test": "vows --spec;jasmine-node spec --coffee --verbose"
2223
}
2324
}

spec/models/user.spec.coffee

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
should = require('should');
2+
User = require('../../models/user');
3+
4+
expectedAttributes =
5+
name: 'Abraham Lincoln'
6+
userSince: Date.parse('April 14, 1865')
7+
slugs: ['abe', 'penniesrock']
8+
handles: [{type: 'twitter', handle: 'abelincoln'}]
9+
credentials: [{provider: 'twitter', id: 1234 }]
10+
_id: 1234
11+
12+
describe 'When creating a user from attributes', ->
13+
user = null
14+
15+
beforeEach ->
16+
user = new User expectedAttributes
17+
18+
it 'should set the correct name', ->
19+
user.attributes.name.should.equal expectedAttributes.name
20+
21+
it 'should set the correct user since date', ->
22+
user.attributes.userSince.should.equal expectedAttributes.userSince
23+
24+
it 'should set the correct slugs', ->
25+
user.attributes.slugs.should.eql expectedAttributes.slugs
26+
27+
it 'should set the correct handles', ->
28+
user.attributes.handles.should.eql expectedAttributes.handles
29+
30+
it 'should set the correct credentials', ->
31+
user.attributes.credentials.should.eql expectedAttributes.credentials
32+
33+
it 'should set the correct id', ->
34+
user.attributes._id.should.equal expectedAttributes._id
35+
36+
describe 'and to toJSON() is called', ->
37+
userJson = null
38+
39+
beforeEach ->
40+
userJson = user.toJSON()
41+
42+
it 'should set the correct name', ->
43+
userJson.name.should.equal expectedAttributes.name
44+
45+
it 'should set the correct user since date', ->
46+
userJson.userSince.should.equal expectedAttributes.userSince
47+
48+
it 'should set the correct slugs', ->
49+
userJson.slugs.should.eql expectedAttributes.slugs
50+
51+
it 'should set the correct handles', ->
52+
userJson.handles.should.eql expectedAttributes.handles
53+
54+
it 'should set the correct credentials', ->
55+
userJson.credentials.should.eql expectedAttributes.credentials
56+
57+
it 'should set the correct id', ->
58+
userJson._id.should.equal expectedAttributes._id
59+
60+
describe 'When creating a user model', ->
61+
user = null
62+
63+
beforeEach () ->
64+
user = new User()
65+
66+
it 'should have default values', ->
67+
should.not.exist user.attributes.name
68+
should.not.exist user.attributes.userSince
69+
should.not.exist user.attributes._id
70+
71+
user.attributes.slugs.should.be.empty
72+
user.attributes.handles.should.be.empty
73+
user.attributes.credentials.should.be.empty
74+
75+
describe 'and toJSON() is called on the new user', ->
76+
userJson = null
77+
78+
beforeEach ->
79+
userJson = user.toJSON()
80+
81+
it 'should not have an id set', ->
82+
should.not.exist userJson._id
83+
84+
it 'should not have a user since date', ->
85+
should.not.exist userJson.userSince
86+
87+
it 'should not have any slugs', ->
88+
userJson.slugs.should.be.empty
89+
90+
it 'should not have any credentials', ->
91+
userJson.credentials.should.be.empty
92+
93+
it 'should not have any handles', ->
94+
userJson.handles.should.be.empty
95+
96+
describe 'and a new credential is added', ->
97+
beforeEach ->
98+
user.setCredential 'twitter', 1865
99+
100+
it 'should have the newly added credential', ->
101+
user.attributes.credentials.length.should.equal 1
102+
user.attributes.credentials[0].provider.should.equal 'twitter'
103+
user.attributes.credentials[0].id.should.equal 1865
104+
105+
describe 'and the same credential is added with different case', ->
106+
107+
beforeEach ->
108+
user.setCredential 'Twitter', 1337
109+
110+
it 'should not add a new credential to the list', ->
111+
user.attributes.credentials.length.should.equal 1
112+
user.attributes.credentials[0].provider.should.equal 'twitter'
113+
user.attributes.credentials[0].id.should.equal 1337
114+
115+
describe 'and a completely different credential is added', ->
116+
beforeEach ->
117+
user.setCredential 'github', 100
118+
119+
it 'should be appended to the credentials', ->
120+
user.attributes.credentials.length.should.equal 2
121+
user.attributes.credentials[1].provider.should.equal 'github'
122+
user.attributes.credentials[1].id.should.equal 100

test/models/user_test.coffee

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)