Skip to content

Commit

Permalink
cli: add simple integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jul 27, 2023
1 parent 0c16bb7 commit b05833e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/integration/bin/cli.js
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';
}

0 comments on commit b05833e

Please sign in to comment.