-
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
0c16bb7
commit b05833e
Showing
1 changed file
with
41 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,41 @@ | ||
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 { | ||
// eslint-disable-next-line no-use-before-define | ||
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', () => { | ||
// eslint-disable-next-line no-use-before-define | ||
const email = randomEmail(); | ||
|
||
// eslint-disable-next-line no-use-before-define | ||
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/); | ||
}); | ||
}); | ||
}); | ||
|
||
function cli(argString, opts) { | ||
return execSync( | ||
'node lib/bin/cli.js ' + argString, | ||
{ encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'], ...opts }, | ||
); | ||
} | ||
|
||
function randomEmail() { | ||
return uuid() + '@example.com'; | ||
} |