'use strict';

const assert = require('assert');
const Images = require('../src/images');

describe('Images', () => {
  describe('#getRandom()', () => {
    let records = {
      '😱': [ 'http://example.com' ]
    };

    it('should return an image', () => {
      let images = new Images(records);
      let image = images.getRandom();

      assert.equal(image.getKey(), '😱');
      assert.equal(image.toString(), 'http://example.com');
    });
  });

  describe('#getFromText', () => {
    describe('emoji present', () => {
      describe('record found and complete', () => {
        describe('sequence length', () => {
          let records = {
            // shorter sequences should be skipped:
            '👩': [ 'http://example.com/woman' ],
            '👦': [ 'http://example.com/boy' ],
            '👩‍👦': [ 'http://example.com/family-woman-boy' ],
            // in favor of longer ones:
            '👩‍👦‍👦': [ 'http://example.com/family-woman-woman-boy' ]
          };

          it('should return a longer sequence over a shorter one', () => {
            let images = new Images(records);
            let image = images.getFromText('@some_bot 👩‍👦‍👦');

            assert.equal(image.getKey(), '👩‍👦‍👦');
            assert.equal(image.toString(), 'http://example.com/family-woman-woman-boy');
          });
        });

        describe('URL length', () => {
          let records = {
            // incomplete records should be skipped:
            '🏿': [],
            // in favor of complete ones:
            '👍': [ 'http://example.com/+1' ]
          };

          it('should return a complete record over an incomplete one', () => {
            let images = new Images(records);
            let image = images.getFromText('@some_bot 👍🏿');

            assert.equal(image.getKey(), '👍');
            assert.equal(image.toString(), 'http://example.com/+1');
          });
        });
      });

      describe('record found, but incomplete', () => {
        let records = {
          '⚙': []
        };

        it('should return a "Not Found" message', () => {
          let images = new Images(records);
          let image = images.getFromText('@some_bot ⚙');

          assert.equal(image.getKey(), '⚙');
          assert.equal(image.toString(), '¯\\_(ツ)_/¯ Try searching digitalcollections.nypl.org for that!');
        });
      });

      describe('record not found', () => {
        let records = {
          '😱': [ 'http://example.com/scream' ],
        };

        it('should return null', () => {
          let images = new Images(records);
          let image = images.getFromText('@some_bot 😖');

          assert.equal(image, null);
        });
      });
    });

    describe('emoji absent', () => {
      let records = {
        '😱': [ 'http://example.com/scream' ],
      };

      it('should return null', () => {
        let images = new Images(records);
        let image = images.getFromText('@some_bot hello');

        assert.equal(image, null);
      });
    });
  });
});

@@ -142,24 +142,66 @@
 )', () =%3E %7B%0A
+    describe('not blacklisted', () =%3E %7B%0A  
     let reco
@@ -204,24 +204,26 @@
 records = %7B%0A
+  
       '%F0%9F%98%B1': %5B
@@ -246,28 +246,32 @@
 .com' %5D%0A    
+  
 %7D;%0A%0A
+  
     it('shou
@@ -291,32 +291,34 @@
 image', () =%3E %7B%0A
+  
       let images
@@ -343,24 +343,26 @@
 rds);%0A      
+  
 let image = 
@@ -378,24 +378,26 @@
 tRandom();%0A%0A
+  
       assert
@@ -427,24 +427,26 @@
 '%F0%9F%98%B1');%0A      
+ 
+ 
 assert.equal
@@ -483,24 +483,316 @@
 mple.com');%0A
+      %7D);%0A    %7D);%0A%0A    describe('blacklisted', () =%3E %7B%0A      let records = %7B%0A        '%F0%9F%94%AB': %5B 'http://example.com' %5D%0A      %7D;%0A%0A      it('should return null', () =%3E %7B%0A        let images = new Images(records);%0A        let image = images.getRandom();%0A%0A        assert.equal(image, null);%0A      %7D);%0A
     %7D);%0A  %7D)

add failing test case