All files / __tests__ mockedSetup.ts

79.16% Statements 19/24
100% Branches 0/0
0% Functions 0/2
79.16% Lines 19/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 507x     7x   7x 7x   7x 7x 7x 7x 7x                         7x           7x                 7x 7x 7x 7x 7x 7x 7x 7x    
import algoliasearch from "algoliasearch";
import {Change} from "firebase-functions";
import {DocumentSnapshot} from "firebase-functions/lib/providers/firestore";
import * as functionsTestInit from "firebase-functions-test";
 
const mockedAlgoliaSearch = jest.mocked(algoliasearch, { shallow: true } );
const mockedAddAlgoliaAgent = jest.fn();
 
const mockedPartialUpdateObject = jest.fn();
const mockedSaveObjects = jest.fn();
const mockedSaveObject = jest.fn();
const mockedDeleteObject = jest.fn();
const mockedInitIndex = jest.fn((): {
  deleteObject: jest.Mock<any, any>;
  saveObjects: jest.Mock<any, any>;
  saveObject: jest.Mock<any, any>;
  partialUpdateObject: jest.Mock<any, any>
} => ({
  saveObjects: mockedSaveObjects,
  saveObject: mockedSaveObject,
  deleteObject: mockedDeleteObject,
  partialUpdateObject: mockedPartialUpdateObject
}));
 
// @ts-ignore
mockedAlgoliaSearch.mockReturnValue({
  addAlgoliaAgent: mockedAddAlgoliaAgent,
  // @ts-ignore
  initIndex: mockedInitIndex
});
 
const mockExport = (document: Change<DocumentSnapshot>, data: Object) => {
  const ref = require('../src/index').executeIndexOperation;
  let functionsTest = functionsTestInit();
 
  const wrapped = functionsTest.wrap(ref);
  return wrapped(document, data);
};
 
export {
  mockedAlgoliaSearch,
  mockedInitIndex,
  mockedAddAlgoliaAgent,
  mockExport,
  mockedPartialUpdateObject,
  mockedSaveObjects,
  mockedSaveObject,
  mockedDeleteObject
}