diff --git a/test/integration/bin/cli.js b/test/integration/bin/cli.js new file mode 100644 index 000000000..76de38d6d --- /dev/null +++ b/test/integration/bin/cli.js @@ -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'; +}