-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate utility functions and business logic
- Loading branch information
Showing
15 changed files
with
150 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install | ||
run: yarn | ||
|
||
- name: Test | ||
run: npm 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
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 |
---|---|---|
@@ -1,57 +1,50 @@ | ||
import { config } from '../src/config'; | ||
import { enableShieldMode, disableShieldMode } from '../src/shield'; | ||
import { readConfig } from '../src/config'; | ||
import { whitelistDistraction } from '../src/whitelist'; | ||
import { enableShieldMode, disableShieldMode } from '../src/shield'; | ||
import { blockDistraction, unblockDistraction } from '../src/block'; | ||
|
||
jest.mock('child_process', () => ({ | ||
execSync: jest.fn().mockImplementation(() => false), | ||
})); | ||
|
||
beforeEach(() => { | ||
config.blocklist = []; | ||
config.whitelist = []; | ||
config.shield = false; | ||
config.password = 'ulysse'; | ||
jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
}); | ||
|
||
test('Should enable shield mode', async () => { | ||
enableShieldMode('ulysse'); | ||
await enableShieldMode('ulysse'); | ||
|
||
const passwordHash = 'd97e609b03de7506d4be3bee29f2431b40e375b33925c2f7de5466ce1928da1b'; | ||
expect(config.passwordHash).toBe(passwordHash); | ||
expect(config.shield).toBe(true); | ||
const { password, passwordHash, shield } = readConfig(); | ||
expect(password).toBeUndefined(); | ||
expect(passwordHash).toBe('d97e609b03de7506d4be3bee29f2431b40e375b33925c2f7de5466ce1928da1b'); | ||
expect(shield).toBe(true); | ||
}); | ||
|
||
test('Should disable shield mode', async () => { | ||
enableShieldMode('ulysse'); | ||
await enableShieldMode('ulysse'); | ||
|
||
disableShieldMode('ulysse'); | ||
await disableShieldMode('ulysse'); | ||
|
||
expect(config.shield).toBe(false); | ||
expect(readConfig().shield).toBe(false); | ||
expect(readConfig().passwordHash).toBeUndefined(); | ||
}); | ||
|
||
test('Should not disable shield mode if bad password', async () => { | ||
enableShieldMode('ulysse'); | ||
|
||
disableShieldMode('badpassword'); | ||
await enableShieldMode('ulysse'); | ||
await disableShieldMode('badpassword'); | ||
|
||
expect(config.shield).toBe(true); | ||
expect(readConfig().shield).toBe(true); | ||
}); | ||
|
||
test('Should not unblock a distraction if shield mode is enabled', async () => { | ||
blockDistraction({ name: 'example.com' }); | ||
enableShieldMode('ulysse'); | ||
await blockDistraction({ name: 'example.com' }); | ||
await enableShieldMode('ulysse'); | ||
|
||
unblockDistraction({ name: 'example.com' }); | ||
await unblockDistraction({ name: 'example.com' }); | ||
|
||
expect(config.blocklist).toEqual([{ name: 'example.com' }]); | ||
expect(readConfig().blocklist).toContainEqual({ name: 'example.com' }); | ||
}); | ||
|
||
test('Should not whitelist a distraction if shield mode is enabled', async () => { | ||
enableShieldMode('ulysse'); | ||
await enableShieldMode('ulysse'); | ||
|
||
whitelistDistraction({ name: 'example.com' }); | ||
await whitelistDistraction({ name: 'example.com' }); | ||
|
||
expect(config.whitelist).toEqual([]); | ||
expect(readConfig().whitelist).not.toContainEqual({ name: 'example.com' }); | ||
}); |
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 @@ | ||
require('dotenv/config'); | ||
const fs = require('fs'); | ||
const { CONFIG_PATH } = require('./src/constants'); | ||
|
||
module.exports = () => { | ||
if (fs.existsSync(CONFIG_PATH)) { | ||
fs.unlinkSync(CONFIG_PATH); | ||
} | ||
|
||
import('./src/socket'); | ||
}; |
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
Oops, something went wrong.