const InvertedIndex = require('../src/inverted-index');
const correctBook = require('../books.json');
const wrongBook = require('../wrongFormat.json');
const emptyBook = require('../emptyBook.json');
const invertedIndex = new InvertedIndex();
invertedIndex.createIndex(correctBook, 'books.json');

describe('Read book data', () => {
  it('Should return false for empty JSON Array', () => {
    expect(invertedIndex.validateFile(emptyBook)[0]).toEqual(false);
  });

  it('Should return true for valid JSON Array', () => {
    expect(invertedIndex.validateFile(correctBook)[0]).toEqual(true);
  });

  it('Should return false for wrong key json file', () => {
    expect(invertedIndex.validateFile(invalidBook)[0]).toEqual(false);
  });
});

describe('Populate Index',() => {
  it('Should create index once JSON file has been read', () => {
    expect().toEqual();
  });

  it('Should ensure each key maps correct object', () => {
    expect(invertedIndex.getIndex('books.json').alice).toEqual([1]);
  });
});

describe('Search Index', () => {
  it('Should return correct index for an array of search terms', () => {
    expect(invertedIndex.searchIndex('books.json', ['alice']).toEqual(
      {'books.json':
    {'alice': [1]}
  }));
  });

  it('Should return correct index results for searched term', () => {
    expect(invertedIndex.searchIndex('books.json','alice and')).toEqual({'alice': [1], 'and': [1,2]});
  });
});
@@ -3,201 +3,323 @@
 nst 
-InvertedIndex = require('../src/inverted-index');%0Aconst correctBook = require('../books.json');%0Aconst wrongBook = require('../wrongFormat.json');%0Aconst emptyBook = require('../emptyBook.json');
+book = %5B%0A  %7B%0A    title: 'Alice in Wonderland',%0A    text: 'Alice falls into a rabbit hole and enters a world full of imagination.'%0A  %7D,%0A%0A  %7B%0A    title: 'The Lord of the Rings: The Fellowship of the Ring.',%0A    text: 'An unusual alliance of man, elf, dwarf, wizard and hobbit seek to destroy a powerful ring.'%0A  %7D%0A%5D;%0A
 %0Acon
@@ -384,24 +384,17 @@
 teIndex(
-correctB
+b
 ook, 'bo
@@ -527,49 +527,35 @@
 dex.
-v
+isV
 alid
-ateFile(emptyBook)%5B0%5D).toEqual(false
+Json(%5B%5D)).toBeFalsy(
 );%0A 
@@ -645,50 +645,38 @@
 dex.
-v
+isV
 alid
-ateFile(correctB
+Json(b
 ook)
-%5B0%5D
 ).to
-Equal(true
+BeTruthy(
 );%0A 
@@ -770,21 +770,21 @@
 dex.
-v
+isV
 alid
-ateFile(
+Json('
 inva
@@ -794,27 +794,22 @@
 Book
-)%5B0%5D).toEqual(false
+')).toBeFalsy(
 );%0A 
@@ -844,16 +844,17 @@
  Index',
+ 
 () =%3E %7B%0A
@@ -1249,17 +1249,16 @@
 n', 
-%5B
 'alice'
-%5D
+)
 ).to
@@ -1275,45 +1275,27 @@
    %7B
-'books.json':%0A    %7B'
+ 
 alice
-'
 : %5B1%5D
-%7D
 %0A  
+    
 %7D
-)
 );%0A 
@@ -1420,16 +1420,17 @@
 s.json',
+ 
 'alice a
@@ -1448,34 +1448,33 @@
 al(%7B
-'
+ 
 alice
-'
 : %5B1%5D, 
-'
 and
-'
 : %5B1,
+ 
 2%5D
+ 
 %7D);%0A
@@ -1470,20 +1470,21 @@
 %5B1, 2%5D %7D);%0A  %7D);%0A%7D);
+%0A

test cases