DataModule.spec.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // @ts-nocheck
  2. import chai from "chai";
  3. import sinon from "sinon";
  4. import sinonChai from "sinon-chai";
  5. import chaiAsPromised from "chai-as-promised";
  6. // import { ObjectId } from "mongodb";
  7. // import JobContext from "@/JobContext";
  8. import JobQueue from "@/JobQueue";
  9. import LogBook from "@/LogBook";
  10. import ModuleManager from "@/ModuleManager";
  11. import DataModule from "./DataModule";
  12. // const should = chai.should();
  13. chai.use(sinonChai);
  14. chai.use(chaiAsPromised);
  15. describe("Data Module", function () {
  16. const moduleManager = Object.getPrototypeOf(
  17. sinon.createStubInstance(ModuleManager)
  18. );
  19. ModuleManager.setPrimaryInstance(moduleManager);
  20. const logBook = sinon.createStubInstance(LogBook);
  21. LogBook.setPrimaryInstance(logBook);
  22. moduleManager.jobQueue = sinon.createStubInstance(JobQueue);
  23. const dataModule = new DataModule();
  24. // const jobContext = sinon.createStubInstance(JobContext);
  25. // const testData = { abc: [] };
  26. before(async function () {
  27. await dataModule.startup();
  28. // dataModule.redisClient = sinon.spy(dataModule.redisClient);
  29. });
  30. // beforeEach(async function () {
  31. // testData.abc = await Promise.all(
  32. // Array.from({ length: 10 }).map(async () => {
  33. // const doc = {
  34. // name: `Test${Math.round(Math.random() * 1000)}`,
  35. // autofill: {
  36. // enabled: !!Math.round(Math.random())
  37. // },
  38. // someNumbers: Array.from({
  39. // length: Math.max(1, Math.round(Math.random() * 50))
  40. // }).map(() => Math.round(Math.random() * 10000)),
  41. // songs: Array.from({
  42. // length: Math.max(1, Math.round(Math.random() * 10))
  43. // }).map(() => ({
  44. // _id: new ObjectId()
  45. // })),
  46. // restrictedName: `RestrictedTest${Math.round(
  47. // Math.random() * 1000
  48. // )}`,
  49. // createdAt: new Date(),
  50. // updatedAt: new Date(),
  51. // testData: true
  52. // };
  53. // const res =
  54. // await dataModule.collections?.abc.collection.insertOne({
  55. // ...doc,
  56. // testData: true
  57. // });
  58. // return { _id: res.insertedId, ...doc };
  59. // })
  60. // );
  61. // });
  62. it("module loaded and started", function () {
  63. logBook.log.should.have.been.called;
  64. dataModule.getName().should.equal("data");
  65. dataModule.getStatus().should.equal("STARTED");
  66. });
  67. afterEach(async function () {
  68. sinon.reset();
  69. // await dataModule.collections?.abc.collection.deleteMany({
  70. // testData: true
  71. // });
  72. });
  73. after(async function () {
  74. await dataModule.shutdown();
  75. });
  76. });