Skip to content

Commit

Permalink
test for sanitize function
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-karatsiuba committed Apr 5, 2023
1 parent 1561f50 commit 2b702ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
9 changes: 0 additions & 9 deletions test/e2e/cmd.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,5 @@ describe('Exec Command With Bash', () => {
/verbose should be empty or one of \[info, log, warn, error, quiet\]/,
)
})

test('Exec Command With doubled options', async () => {
await expect(execa(`${mwo} --verbose --mwUrl="https://en.wikipedia.org" --adminEmail="[email protected]" --verbose=info`, { shell: true })).rejects.toThrow(
/Parameter verbose can only be used once/,
)
await expect(execa(`${mwo} --verbose --mwUrl="https://en.wikipedia.org" --adminEmail="[email protected]" --mwUrl="https://en.wikipedia.org"`, { shell: true })).rejects.toThrow(
/Parameter mwUrl can only be used once/,
)
})
})
})
47 changes: 47 additions & 0 deletions test/unit/sanitize-argument.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { sanitize_all } from '../../src/sanitize-argument.js'

describe('Sanitize parameters', () => {
test('sanitizing usage of the same parameter more than one time', async () => {
// equivalent to command: node lib/cli.js --verbose --mwUrl="https://en.wikipedia.org" --adminEmail="[email protected]" --verbose=info
const twoVerboseParameters = {
_: [],
verbose: [true, 'info'],
mwUrl: 'https://en.wikipedia.org',
'mw-url': 'https://en.wikipedia.org',
adminEmail: '[email protected]',
'admin-email': '[email protected]',
$0: 'node_modules/ts-node/dist/child/child-entrypoint.js',
}

await expect(sanitize_all(twoVerboseParameters)).rejects.toThrow(/Parameter '--verbose' can only be used once/)

// equivalent to command: node lib/cli.js --verbose --mwUrl="https://en.wikipedia.org" --adminEmail="[email protected]" --mwUrl="https://en.wikipedia.org"
const twoUrlParameters = {
_: [],
verbose: true,
mwUrl: ['https://en.wikipedia.org', 'https://en.wikipedia.org'],
'mw-url': ['https://en.wikipedia.org', 'https://en.wikipedia.org'],
adminEmail: '[email protected]',
'admin-email': '[email protected]',
$0: 'node_modules/ts-node/dist/child/child-entrypoint.js',
}

await expect(sanitize_all(twoUrlParameters)).rejects.toThrow(/Parameter '--mwUrl' can only be used once/)

// equivalent to command: node lib/cli.js --verbose=info --adminEmail="[email protected]" --articleList="User:Kelson/MWoffliner_CI_reference" --mwUrl="https://en.m.wikipedia.org/" --format=nopic --format=nopdf --format=novid
const threeFormatParameters = {
_: [],
verbose: 'info',
adminEmail: '[email protected]',
'admin-email': '[email protected]',
articleList: 'User:Kelson/MWoffliner_CI_reference',
'article-list': 'User:Kelson/MWoffliner_CI_reference',
mwUrl: 'https://en.m.wikipedia.org/',
'mw-url': 'https://en.m.wikipedia.org/',
format: ['nopic', 'nopdf', 'novid'],
$0: 'node_modules/ts-node/dist/child/child-entrypoint.js',
}

expect(await sanitize_all(threeFormatParameters)).toBeUndefined()
})
})

0 comments on commit 2b702ac

Please sign in to comment.