Skip to content

Commit

Permalink
Mock server responses with Sinon
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Jan 20, 2017
1 parent fda7963 commit cc6d2d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ module.exports = ->
noflo_browser_mocha:
all:
options:
scripts: ["../browser/<%=pkg.name%>.js"]
scripts: [
"../browser/<%=pkg.name%>.js"
'../node_modules/sinon/pkg/sinon-server.js'
]
files:
'spec/tests.html': ['spec/*.js', '!spec/EndToEnd*.js']
# BDD tests on browser
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"grunt-vulcanize": "^0.4.2",
"grunt-zip": "^0.17.0",
"mocha": "^3.2.0",
"sinon": "^1.17.7",
"syn": "0.2.2",
"yaml-include-loader": "^1.0.0"
},
Expand Down
28 changes: 24 additions & 4 deletions spec/UserMiddleware.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe 'User Middleware', ->
pass: false
user: false
action = 'start'
payload = true
payload = 'https://app.flowhub.io'
receivePass passAction, action, payload, ->
received.pass = true
return unless received.user
Expand All @@ -122,6 +122,29 @@ describe 'User Middleware', ->
return unless received.pass
done()
send actionIn, action, payload
describe 'without user and with invalid grant code in URL', ->
xhr = null
code = null
beforeEach ->
code = 'dj0328hf3d9cq3c'
xhr = sinon.fakeServer.create()
afterEach ->
xhr.restore()
it 'should perform a token exchange and fail', (done) ->
action = 'start'
payload = "https://app.flowhub.io?code=#{code}"
check = (data) ->
chai.expect(data.message).to.contain 'bad_code_foo'
receiveAction newAction, 'user:error', check, done
send actionIn, action, payload
xhr.respondWith 'GET', "https://noflo-gate.herokuapp.com/authenticate/#{code}", [
402
,
'Content-Type': 'application/json'
, JSON.stringify
error: 'bad_code_foo'
]
do xhr.respond
describe 'receiving user:logout action', ->
originalUser = null
userData =
Expand All @@ -134,9 +157,6 @@ describe 'User Middleware', ->
return unless originalUser
localStorage.setItem 'grid-user', originalUser
it 'should send empty object as user:info', (done) ->
received =
pass: false
user: false
action = 'user:logout'
check = (data) ->
chai.expect(data).to.eql {}
Expand Down

0 comments on commit cc6d2d6

Please sign in to comment.