Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow authored and aduh95 committed Mar 15, 2023
1 parent 2dd1257 commit f12d06b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
12 changes: 0 additions & 12 deletions test/unit/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,34 @@ const MOCKED_TOKEN = JSON.stringify({

describe('auth', async function() {
it('asks for auth data if no ncurc is found', async function() {
this.timeout(2000);
await runAuthScript(
undefined,
[FIRST_TIME_MSG, MOCKED_TOKEN]
);
});

it('asks for auth data if ncurc is invalid json', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: 'this is not json' },
[FIRST_TIME_MSG, MOCKED_TOKEN]
);
});

it('returns ncurc data if valid in HOME', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789abcdef' } },
[MOCKED_TOKEN]
);
});

it('returns ncurc data if valid in XDG_CONFIG_HOME', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789abcdef' } },
[MOCKED_TOKEN]
);
});

it('prefers XDG_CONFIG_HOME/ncurc to HOME/.ncurc', async function() {
this.timeout(2000);
await runAuthScript(
{
HOME: { username: 'notnyancat', token: 'somewrongtoken' },
Expand All @@ -62,7 +57,6 @@ describe('auth', async function() {
});

it("prints an error message if it can't generate a token", async function() {
this.timeout(2000);
await runAuthScript(
{},
[FIRST_TIME_MSG],
Expand All @@ -71,7 +65,6 @@ describe('auth', async function() {
});

it('does not accept a non-string username', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: {}, token: '0123456789abcdef' } },
[],
Expand All @@ -80,7 +73,6 @@ describe('auth', async function() {
});

it('does not accept a non-string token', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: 42 } },
[],
Expand All @@ -89,7 +81,6 @@ describe('auth', async function() {
});

it('does not accept an invalid username format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: ' ^^^ ', token: '0123456789abcdef' } },
[],
Expand All @@ -99,7 +90,6 @@ describe('auth', async function() {
});

it('does not accept an invalid token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '@fhqwhgads' } },
[],
Expand All @@ -108,15 +98,13 @@ describe('auth', async function() {
});

it('permits capital letters in token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789ABCDEF' } },
['{"github":"bnlhbmNhdDowMTIzNDU2Nzg5QUJDREVG"}']
);
});

it('permits underscores in token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: 'ghp_0123456789ABCDEF' } },
['{"github":"bnlhbmNhdDpnaHBfMDEyMzQ1Njc4OUFCQ0RFRg=="}']
Expand Down
39 changes: 38 additions & 1 deletion test/unit/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe('cli', () => {

describe('spinners', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
cli.startSpinner('foo');
});

Expand All @@ -59,20 +61,34 @@ describe('cli', () => {
});

describe('write', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should write in stream', () => {
const stream = new LogStream();
const cli = new CLI(stream);
cli.write('Getting commits...');
assert.strictEqual(logResult(), 'Getting commits...');
assert.strictEqual(strip(stream.toString()), 'Getting commits...');
});
});

describe('log', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should write in stream', () => {
cli.log('Getting commits...');
assert.strictEqual(logResult(), 'Getting commits...\n');
});
});

describe('table', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print the first element with bold style and padding', () => {
cli.table('Title', 'description');
assert.strictEqual(logResult(),
Expand All @@ -81,6 +97,10 @@ describe('cli', () => {
});

describe('separator', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print a separator line with the specified text', () => {
cli.separator('Separator');
assert.strictEqual(
Expand All @@ -106,6 +126,10 @@ describe('cli', () => {
});

describe('ok', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print a success message', () => {
cli.ok('Perfect!');
assert.strictEqual(logResult(), ` ${success} Perfect!\n`);
Expand All @@ -119,6 +143,10 @@ describe('cli', () => {
});

describe('warn', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print a warning message', () => {
cli.warn('Warning!');
assert.strictEqual(logResult(), ` ${warning} Warning!\n`);
Expand All @@ -132,6 +160,10 @@ describe('cli', () => {
});

describe('info', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print an info message', () => {
cli.info('Info!');
assert.strictEqual(logResult(), ` ${info} Info!\n`);
Expand All @@ -144,6 +176,10 @@ describe('cli', () => {
});

describe('error', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print an error message', () => {
cli.error('Error!');
assert.strictEqual(logResult(), ` ${error} Error!\n`);
Expand Down Expand Up @@ -184,6 +220,7 @@ describe('cli', () => {
questionType: cli.QUESTION_TYPE.INPUT
});
assert.strictEqual(cli.spinner.isSpinning, true);
cli.stopSpinner('foo');
});
});

Expand Down

0 comments on commit f12d06b

Please sign in to comment.