You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.9 KiB
130 lines
3.9 KiB
import { parse_args } from '../src/logic'; |
|
|
|
const process = require('process'); |
|
const process_mock = jest.spyOn(process, 'exit').mockImplementation(() => true); |
|
|
|
describe('test parse args', () => { |
|
it('parses a single page id with -p', () => { |
|
const res = parse_args(['-p', 'foo']); |
|
expect(res.page_ids).toEqual(['https://www.facebook.com/foo/events/']); |
|
}); |
|
|
|
it('parses a single page id with -p', () => { |
|
const res = parse_args(['-p', '"foo"']); |
|
expect(res.page_ids).toEqual(['https://www.facebook.com/foo/events/']); |
|
}); |
|
|
|
it('parses a single page id with --page', () => { |
|
const res = parse_args(['--page=foo']); |
|
expect(res.page_ids).toEqual(['https://www.facebook.com/foo/events/']); |
|
}); |
|
|
|
it('parses a single page id with --page', () => { |
|
const res = parse_args(['--page="foo"']); |
|
expect(res.page_ids).toEqual(['https://www.facebook.com/foo/events/']); |
|
}); |
|
|
|
it('parses multiple page ids with --pages', () => { |
|
const res = parse_args(['--pages=foo,bar']); |
|
expect(res.page_ids).toEqual([ |
|
'https://www.facebook.com/foo/events/', |
|
'https://www.facebook.com/bar/events/', |
|
]); |
|
}); |
|
|
|
it('parses multiple page ids with --pages', () => { |
|
const res = parse_args(['--pages="foo,bar"']); |
|
expect(res.page_ids).toEqual([ |
|
'https://www.facebook.com/foo/events/', |
|
'https://www.facebook.com/bar/events/', |
|
]); |
|
}); |
|
|
|
['-?', '--help', '-h'].forEach((param) => { |
|
it('parses help options', () => { |
|
const res = parse_args([param]); |
|
expect(process_mock).toHaveBeenCalledWith(1); |
|
}); |
|
}); |
|
|
|
it('parses event option', () => { |
|
const res = parse_args(['--events=events.json']); |
|
expect(res.events).toEqual('events.json'); |
|
}); |
|
|
|
it('parses event option', () => { |
|
const res = parse_args(['--events="events.json"']); |
|
expect(res.events).toEqual('events.json'); |
|
}); |
|
|
|
it('sets events to null if no option is passed', () => { |
|
const res = parse_args(['']); |
|
expect(res.events).toEqual(null); |
|
}); |
|
|
|
it('sets output to null if no option is passed', () => { |
|
const res = parse_args(['']); |
|
expect(res.output).toEqual(null); |
|
}); |
|
|
|
it('passes output if it is set with --output', () => { |
|
const res = parse_args(['--output=jacobi']); |
|
expect(res.output).toEqual('jacobi'); |
|
}); |
|
|
|
it('passes output if it is set with --output', () => { |
|
const res = parse_args(['--output="jacobi"']); |
|
expect(res.output).toEqual('jacobi'); |
|
}); |
|
|
|
it('passes output if it is set with -o', () => { |
|
const res = parse_args(['-o', 'jacobi']); |
|
expect(res.output).toEqual('jacobi'); |
|
}); |
|
|
|
it('passes output if it is set with -o', () => { |
|
const res = parse_args(['-o', '"jacobi"']); |
|
expect(res.output).toEqual('jacobi'); |
|
}); |
|
|
|
['--images', '-i'].forEach((param) => { |
|
it('parses image options', () => { |
|
const res = parse_args([param]); |
|
expect(res.images).toEqual(true); |
|
}); |
|
}); |
|
|
|
[ |
|
['--image-directory=img'], |
|
['--image-directory="img"'], |
|
["--image-directory='img'"], |
|
['--image-directory', 'img'], |
|
['--image-directory', '"img"'], |
|
['--image-directory', "'img'"], |
|
].forEach((param) => { |
|
it('parses image_directory options', () => { |
|
const res = parse_args(param); |
|
expect(res.image_directory).toEqual('img'); |
|
}); |
|
}); |
|
|
|
it('parses skip upcoming events option', () => { |
|
const res = parse_args(['--skip-upcoming-events']); |
|
expect(res.get_upcoming_events).toEqual(false); |
|
}); |
|
|
|
it('sets the correct default value for getting upcoming events', () => { |
|
const res = parse_args([]); |
|
expect(res.get_upcoming_events).toEqual(true); |
|
}); |
|
|
|
it('sets the correct default value for getting upcoming events', () => { |
|
const res = parse_args([]); |
|
expect(res.get_past_events).toEqual(false); |
|
}); |
|
|
|
it('parses skip upcoming events option', () => { |
|
const res = parse_args(['--past-events']); |
|
expect(res.get_past_events).toEqual(true); |
|
}); |
|
});
|
|
|