-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set proper settings with given args and json file
resolves #18
- Loading branch information
Showing
3 changed files
with
119 additions
and
4 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,89 @@ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
|
||
import { Arguments } from './Arguments' | ||
|
||
describe('Arguments', () => { | ||
let args: Arguments | ||
|
||
beforeEach(() => { | ||
process.argv = process.argv.slice(0, 2) | ||
}) | ||
|
||
it('should be created', () => { | ||
args = new Arguments() | ||
|
||
expect(args).toBeDefined() | ||
}) | ||
|
||
it('should match snapshot', () => { | ||
args = new Arguments() | ||
|
||
expect(args.settings).toMatchSnapshot() | ||
}) | ||
|
||
describe('with command line options', () => { | ||
it('should set number', () => { | ||
process.argv = process.argv.concat('--port', '1337') | ||
|
||
args = new Arguments() | ||
|
||
expect(args.settings.port).toEqual(1337) | ||
}) | ||
|
||
it('should set string', () => { | ||
process.argv = process.argv.concat('--name', 'server') | ||
|
||
args = new Arguments() | ||
|
||
expect(args.settings.name).toEqual('server') | ||
}) | ||
|
||
it('should set boolean', () => { | ||
process.argv = process.argv.concat('--disableGamemodeVote') | ||
|
||
args = new Arguments() | ||
|
||
expect(args.settings.enableGamemodeVote).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('with JSON options', () => { | ||
beforeEach(() => { | ||
jest.mock('fs') | ||
}) | ||
|
||
it('should set number', () => { | ||
const mockSettings = JSON.stringify({ | ||
port: 1337 | ||
}) | ||
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => mockSettings) | ||
|
||
args = new Arguments() | ||
|
||
expect(args.settings.port).toEqual(1337) | ||
}) | ||
|
||
it('should set string', () => { | ||
const mockSettings = JSON.stringify({ | ||
name: 'server' | ||
}) | ||
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => mockSettings) | ||
|
||
args = new Arguments() | ||
|
||
expect(args.settings.name).toEqual('server') | ||
}) | ||
|
||
it('should set boolean', () => { | ||
const mockSettings = JSON.stringify({ | ||
enableGamemodeVote: false | ||
}) | ||
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => mockSettings) | ||
|
||
args = new Arguments() | ||
|
||
expect(args.settings.enableGamemodeVote).toBe(false) | ||
}) | ||
}) | ||
}) |
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,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Arguments should match snapshot 1`] = ` | ||
Object { | ||
"apiKey": "", | ||
"description": "The **best** Net64+ server ever | ||
:unicorn_face:", | ||
"domain": "", | ||
"enableGamemodeVote": true, | ||
"enableWebHook": false, | ||
"gamemode": 1, | ||
"name": "A Net64+ Server", | ||
"password": "", | ||
"passwordRequired": false, | ||
"port": 3678, | ||
} | ||
`; |