-
Notifications
You must be signed in to change notification settings - Fork 4
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
6 changed files
with
1,712 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint-staged | ||
CI=true yarn run test |
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,61 @@ | ||
const mockeData = require('./utils'); | ||
const Master = require('../index'); | ||
|
||
process.env.transferEncryptToken = '00000000000000000000000000000000'; | ||
process.env.token = 'demoCHannel0'; | ||
process.env.LOG_LEVEL = 'off'; | ||
|
||
let master; | ||
beforeEach(() => { | ||
master = new Master(); | ||
}); | ||
|
||
describe('pushNewJob method', () => { | ||
it('Reject push job if not pass payload', async () => { | ||
await master.pushNewJob().catch((e) => { | ||
expect(e.message).toBe('payload is undefined'); | ||
}); | ||
}); | ||
it('Push job succesfully and enrcypted , if job is object', async () => { | ||
const encryptedPayload = master.crypt.encrypt( | ||
JSON.stringify(mockeData.payloadObject) | ||
); | ||
await master.pushNewJob(mockeData.payloadObject); | ||
|
||
expect(encryptedPayload).toHaveProperty('iv'); | ||
expect(encryptedPayload).toHaveProperty('encryptedData'); | ||
expect(master.jobs).toHaveLength(1); | ||
expect(JSON.parse(master.jobs[0])).toEqual(encryptedPayload); | ||
}); | ||
it('Push job succesfully and enrcypted , if job is array', async () => { | ||
const encryptedPayload = master.crypt.encrypt( | ||
JSON.stringify(mockeData.payloadArray) | ||
); | ||
await master.pushNewJob(mockeData.payloadArray); | ||
|
||
expect(encryptedPayload).toHaveProperty('iv'); | ||
expect(encryptedPayload).toHaveProperty('encryptedData'); | ||
expect(master.jobs).toHaveLength(1); | ||
expect(JSON.parse(master.jobs[0])).toEqual(encryptedPayload); | ||
}); | ||
it('Push job succesfully and enrcypted , if job is string', async () => { | ||
const jobData = '50'; | ||
const encryptedPayload = master.crypt.encrypt(jobData); | ||
await master.pushNewJob(jobData); | ||
|
||
expect(encryptedPayload).toHaveProperty('iv'); | ||
expect(encryptedPayload).toHaveProperty('encryptedData'); | ||
expect(master.jobs).toHaveLength(1); | ||
expect(JSON.parse(master.jobs[0])).toEqual(encryptedPayload); | ||
}); | ||
it('Push job succesfully and enrcypted , if job is number', async () => { | ||
const jobData = 50; | ||
const encryptedPayload = master.crypt.encrypt(jobData); | ||
await master.pushNewJob(jobData); | ||
|
||
expect(encryptedPayload).toHaveProperty('iv'); | ||
expect(encryptedPayload).toHaveProperty('encryptedData'); | ||
expect(master.jobs).toHaveLength(1); | ||
expect(JSON.parse(master.jobs[0])).toEqual(encryptedPayload); | ||
}); | ||
}); |
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 @@ | ||
module.exports = { | ||
payloadObject: { | ||
a: 1, | ||
b: 2, | ||
}, | ||
payloadArray: [ | ||
{ a: 1, b: 2 }, | ||
{ a: 10, b: 20 }, | ||
], | ||
}; |
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
Oops, something went wrong.