Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
test: test if a user is created on first connection
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Jan 21, 2020
1 parent dec72bb commit 767c365
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/chai-things": "0.0.34",
"@types/express": "^4.17.2",
"@types/hapi__joi": "^16.0.6",
"@types/mocha": "^5.2.7",
Expand All @@ -45,6 +46,7 @@
"@types/socket.io-client": "^1.4.32",
"@types/uuid": "^3.4.6",
"chai": "^4.2.0",
"chai-things": "^0.2.0",
"concurrently": "^5.0.2",
"heroku": "^7.36.2",
"husky": "^4.0.10",
Expand Down
22 changes: 16 additions & 6 deletions src/socket.io/socket.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import ioClient from 'socket.io-client'
import io from 'socket.io'
import { expect } from 'chai'
import { default as chai, expect } from 'chai'
import chaiThings from 'chai-things'
chai.should()
chai.use(chaiThings)

import { MockLogger } from '../shared/index'
import { Socket } from './socket'
Expand Down Expand Up @@ -45,6 +48,16 @@ describe('Server', () => {
done()
})
})
it('should create a new user', () => {
new Promise(resolve => client.on('connect', resolve))
.then(() => {
const logs = mockLogger.getInfoLogs()
logs.should.include.something.that.have.string(
'New user created for socket'
)
})
.then(() => client.disconnect())
})
})

describe('update-user-name', () => {
Expand Down Expand Up @@ -84,11 +97,8 @@ describe('Server', () => {
),
])
.then(() => {
const errorLogs = mockLogger.getErrorLogs()
expect(errorLogs).to.have.length(0)
const infoLogs = mockLogger.getInfoLogs()
expect(infoLogs).to.have.length(1)
expect(infoLogs[0]).to.equal(
const logs = mockLogger.getInfoLogs()
logs.should.include.something.that.equals(
`User name could not be updated - Parameter <Object>.${expectedParameter} is required`
)
done()
Expand Down
1 change: 1 addition & 0 deletions src/socket.io/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Socket {
if (user === undefined) {
const newUser = new User(id)
this.users.set(id, newUser)
this.log.info(`getOrCreateUser`, `New user created for socket ${id}`)
return newUser
}
return user
Expand Down

0 comments on commit 767c365

Please sign in to comment.