Skip to content

Commit

Permalink
Fix issues with status and set-params
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schellinger committed Aug 17, 2024
1 parent 77256c9 commit bbb1cb3
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 101 deletions.
46 changes: 23 additions & 23 deletions src/app/commands/params/set-params.command.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParamsKey } from './params.enum';
import { parse } from './set-params.command';
import { convertTo } from './set-params.command';

describe('setParams', () => {
let log: jest.Mock;
Expand All @@ -15,63 +15,63 @@ describe('setParams', () => {

it('should accept valid admins', () => {
const mockOptions = { admins: 'johndoe1,jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.ADMINS, ParameterValue: mockOptions.admins }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.ADMINS]: mockOptions.admins });
expect(log).not.toHaveBeenCalled();
});

it('should discard admins when there is a space in the delimiter', () => {
const mockOptions = { admins: 'johndoe1, jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({ '-a, --admins': 'invalid name format for one or more admins' });
});

it('should discard admins when there is a space in one name', () => {
const mockOptions = { admins: 'john doe1,jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({ '-a, --admins': 'invalid name format for one or more admins' });
});

it('should discard admins when there is a symbol other than underscore in one name', () => {
const mockOptions = { admins: 'john-doe1,jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({ '-a, --admins': 'invalid name format for one or more admins' });
});

it('should accept valid difficulty', () => {
const mockOptions = { difficulty: 'peaceful' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.DIFFICULTY, ParameterValue: mockOptions.difficulty }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.DIFFICULTY]: mockOptions.difficulty });
expect(log).not.toHaveBeenCalled();
});

it('should discard invalid difficulty', () => {
const mockOptions = { difficulty: 'foo' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({ '-d, --difficulty': 'valid values are [peaceful|easy|normal|hard]' });
});

it('should accept valid gamemode', () => {
const mockOptions = { gamemode: 'creative' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.GAMEMODE, ParameterValue: mockOptions.gamemode }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.GAMEMODE]: mockOptions.gamemode });
expect(log).not.toHaveBeenCalled();
});

it('should discard invalid gamemode', () => {
const mockOptions = { gamemode: 'foo' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -81,15 +81,15 @@ describe('setParams', () => {

it('should accept valid mem', () => {
const mockOptions = { mem: '4G' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.MEMORY, ParameterValue: mockOptions.mem }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.MEMORY]: mockOptions.mem });
expect(log).not.toHaveBeenCalled();
});

it('should discard invalid mem', () => {
const mockOptions = { mem: 'foo' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -99,15 +99,15 @@ describe('setParams', () => {

it('should accept valid playermax', () => {
const mockOptions = { playermax: '20' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.PLAYERS_MAX, ParameterValue: mockOptions.playermax }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.PLAYERS_MAX]: mockOptions.playermax });
expect(log).not.toHaveBeenCalled();
});

it('should discard invalid playermax', () => {
const mockOptions = { playermax: 'foo' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -117,15 +117,15 @@ describe('setParams', () => {

it('should accept valid state', () => {
const mockOptions = { state: 'stopped' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.SERVER_STATE, ParameterValue: mockOptions.state }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.SERVER_STATE]: mockOptions.state });
expect(log).not.toHaveBeenCalled();
});

it('should discard invalid state', () => {
const mockOptions = { state: 'foo' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -135,15 +135,15 @@ describe('setParams', () => {

it('should accept valid viewdist', () => {
const mockOptions = { viewdist: '10' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.VIEW_DIST, ParameterValue: mockOptions.viewdist }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.VIEW_DIST]: mockOptions.viewdist });
expect(log).not.toHaveBeenCalled();
});

it('should discard viewdist less than 1', () => {
const mockOptions = { viewdist: '0' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -153,7 +153,7 @@ describe('setParams', () => {

it('should discard viewdist greater than 20', () => {
const mockOptions = { viewdist: 21 };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -163,15 +163,15 @@ describe('setParams', () => {

it('should accept valid whitelist', () => {
const mockOptions = { whitelist: 'johndoe1,jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.WHITELIST, ParameterValue: mockOptions.whitelist }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.WHITELIST]: mockOptions.whitelist });
expect(log).not.toHaveBeenCalled();
});

it('should discard whitelist when there is a space in the delimiter', () => {
const mockOptions = { whitelist: 'johndoe1, jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -181,7 +181,7 @@ describe('setParams', () => {

it('should discard whitelist when there is a space in one name', () => {
const mockOptions = { whitelist: 'john doe1,jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -191,7 +191,7 @@ describe('setParams', () => {

it('should discard whitelist when there is a symbol other than underscore in one name', () => {
const mockOptions = { whitelist: 'john-doe1,jane_doe' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([]);
expect(log).toHaveBeenCalledWith('discarded invalid parameters');
expect(logTable).toHaveBeenCalledWith({
Expand All @@ -201,7 +201,7 @@ describe('setParams', () => {

it('should accept a valid timezone', () => {
const mockOptions = { timezone: 'America/New York' };
const output = parse(mockOptions);
const output = convertTo(mockOptions);
expect(output).toStrictEqual([{ ParameterKey: ParamsKey.TIMEZONE, ParameterValue: mockOptions.timezone }]);
expect(logTable).toHaveBeenCalledWith({ [ParamsKey.TIMEZONE]: mockOptions.timezone });
expect(log).not.toHaveBeenCalled();
Expand Down
Loading

0 comments on commit bbb1cb3

Please sign in to comment.