Unverified Commit cb480919 authored by Bruno Saboia's avatar Bruno Saboia Committed by GitHub
Browse files

Improve tests (#407)

* Improve tests

This PR adds some necessary tests, fixes the naming on describe
(everything was set to RandomKeyGenerator, perhaps a copy/paste
exception) and fixes the consonant/vowel alternation test, since it was
failing if the keyspace started with a vowel.

* Remove unecessary file
parent 00d84614
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ const fs = require('fs');

const Generator = require('../../lib/key_generators/dictionary');

describe('RandomKeyGenerator', function() {
  describe('randomKey', function() {
describe('DictionaryGenerator', function() {
  describe('options', function() {
    it('should throw an error if given no options', () => {
      assert.throws(() => {
        new Generator();
@@ -19,7 +19,8 @@ describe('RandomKeyGenerator', function() {
        new Generator({});
      }, Error);
    });

  });
  describe('generation', function() {
    it('should return a key of the proper number of words from the given dictionary', () => {
      const path = '/tmp/haste-server-test-dictionary';
      const words = ['cat'];
+13 −5
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@ const Generator = require('../../lib/key_generators/phonetic');
const vowels = 'aeiou';
const consonants = 'bcdfghjklmnpqrstvwxyz';

describe('RandomKeyGenerator', () => {
  describe('randomKey', () => {
describe('PhoneticKeyGenerator', () => {
  describe('generation', () => {
    it('should return a key of the proper length', () => {
      const gen = new Generator();
      assert.equal(6, gen.createKey(6).length);
@@ -19,9 +19,17 @@ describe('RandomKeyGenerator', () => {

      const key = gen.createKey(3);

      // if it starts with a consonant, we expect cvc
      // if it starts with a vowel, we expect vcv
      if(consonants.includes(key[0])) {
        assert.ok(consonants.includes(key[0]));
        assert.ok(consonants.includes(key[2]));
        assert.ok(vowels.includes(key[1]));
      } else {
        assert.ok(vowels.includes(key[0]));
        assert.ok(vowels.includes(key[2]));
        assert.ok(consonants.includes(key[1]));
      }
    });
  });
});
+8 −3
Original line number Diff line number Diff line
@@ -5,15 +5,20 @@ const assert = require('assert');
const Generator = require('../../lib/key_generators/random');

describe('RandomKeyGenerator', () => {
  describe('randomKey', () => {
  describe('generation', () => {
    it('should return a key of the proper length', () => {
      const gen = new Generator();
      assert.equal(6, gen.createKey(6).length);
      assert.equal(gen.createKey(6).length, 6);
    });

    it('should use a key from the given keyset if given', () => {
      const gen = new Generator({keyspace: 'A'});
      assert.equal('AAAAAA', gen.createKey(6));
      assert.equal(gen.createKey(6), 'AAAAAA');
    });

    it('should not use a key from the given keyset if not given', () => {
      const gen = new Generator({keyspace: 'A'});
      assert.ok(!gen.createKey(6).includes('B'));
    });
  });
});