-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alxndrsn
committed
Jul 27, 2023
1 parent
d8615db
commit a760276
Showing
1 changed file
with
40 additions
and
0 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,40 @@ | ||
const { execSync } = require('node:child_process'); | ||
const uuid = require('uuid').v4; | ||
|
||
describe('cli', () => { | ||
it('should return status code 1 if no command is issued', () => { | ||
let thrown = false; // pattern from test/unit/util/crypto.js | ||
try { | ||
cli('--email example@example.com'); | ||
} catch (err) { | ||
err.status.should.equal(1); | ||
thrown = true; | ||
} | ||
thrown.should.equal(true); | ||
}); | ||
|
||
describe('command: user-create', () => { | ||
it('should return status code 0 and user details on success', () => { | ||
const email = randomEmail(); | ||
|
||
const [, , js] = cli(`--email ${email} user-create`, { input: 'strong-password-101' }) | ||
.match(/^([^{]*)(.*)$/ms); | ||
|
||
js.should.match(new RegExp(`email: '${email}',`)); | ||
js.should.not.match(/password/); | ||
}); | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line no-use-before-define | ||
function cli(argString, opts) { | ||
return execSync( | ||
'node lib/bin/cli.js ' + argString, | ||
{ encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'], ...opts }, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line no-use-before-define | ||
function randomEmail() { | ||
return uuid() + '@example.com'; | ||
} |