-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Leader class and add new test case
- Loading branch information
1 parent
5f8e21f
commit f3543a0
Showing
6 changed files
with
69 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const { describe, it, expect, afterEach } = require('@jest/globals') | ||
|
||
describe('Your Test Suite', () => { | ||
it('should test something', () => { | ||
// Your test code here | ||
}) | ||
const { Leader } = require('../index') | ||
const { mockDb } = require('./mockDb') | ||
|
||
describe('Leader', () => { | ||
describe('constructor', () => { | ||
it('should set default options', function () { | ||
// Act | ||
const leader = new Leader(mockDb) | ||
|
||
it('should test something else', () => { | ||
// Your test code here | ||
// Assert | ||
expect(leader.db).toBe(mockDb) | ||
expect(leader.options).not.toBeNull() | ||
expect(leader.options.ttl).toBe(1000) | ||
expect(leader.options.wait).toBe(100) | ||
expect(leader.key).toMatch(/^leader-?/) | ||
}) | ||
}) | ||
}) |
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,32 @@ | ||
'use strict' | ||
|
||
const mockAdmin = { | ||
command: () => Promise.resolve(), | ||
} | ||
|
||
const mockDb = { | ||
command: () => Promise.resolve({}), | ||
admin: () => mockAdmin, | ||
listCollections() { | ||
return { | ||
hasNext() { | ||
return Promise.resolve(false) | ||
}, | ||
} | ||
}, | ||
collection(key) { | ||
return { | ||
createIndex() { | ||
return Promise.resolve() | ||
}, | ||
findOneAndUpdate() { | ||
return Promise.resolve() | ||
}, | ||
} | ||
}, | ||
createCollection() { | ||
return Promise.resolve() | ||
}, | ||
} | ||
|
||
module.exports = { mockAdmin, mockDb } |