-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const socketNotif = (receiverId, data, connectedClients, io) => { | ||
if (!receiverId) { | ||
io.emit('notification', data); | ||
} else if (connectedClients[receiverId.toString()]) { | ||
connectedClients[receiverId.toString()].forEach(element => { | ||
io.to(element).emit('notification', data); | ||
}); | ||
} | ||
}; | ||
|
||
export default socketNotif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import jwt from 'jsonwebtoken'; | ||
|
||
export default token => { | ||
try { | ||
const verifiedUser = jwt.verify(token, process.env.JWT_SECRET); | ||
return verifiedUser; | ||
} catch (error) { | ||
return error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import chai from 'chai'; | ||
import decodeToken from '../../middlewares/auth/decodeToken'; | ||
import generateToken from '../../utils/generateToken'; | ||
import mockData from '../mockData/mockData'; | ||
|
||
|
||
const { expect } = chai; | ||
describe('Decode Token test', () => { | ||
it('Should decode the token', (done) => { | ||
try { | ||
decodeToken(generateToken(mockData.verifiedUser1)); | ||
} catch (error) { | ||
expect(error).to.be.null; | ||
} | ||
done(); | ||
}); | ||
|
||
it('Should not decode the token', (done) => { | ||
try { | ||
decodeToken('malformed token'); | ||
} catch (error) { | ||
console.log('error ===>', error); | ||
expect(error).to.be.an('object');; | ||
} | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import chai from 'chai'; | ||
// import { io } from '../../index'; | ||
import socketNotif from '../../helpers/socketNotif'; | ||
|
||
const { expect } = chai; | ||
describe('Socket Notif Test', () => { | ||
it('Should emit to one', (done) => { | ||
socketNotif(1, {}, {'1': ['jhjhjh', 'mnjhj'], io: {to: () => {}, emit: () => {}, }}); | ||
done(); | ||
}); | ||
|
||
it('Should emit to all', (done) => { | ||
socketNotif(undefined, {}, {'1': ['jhjhjh', 'mnjhj'], io: {to: () => {}, emit: () => {}, }}); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters