nested-real.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. tap.test("RecordImport.advance", (t) => {
  2. const checkStates = (batches, states) => {
  3. t.equal(batches.length, states.length);
  4. for (const batch of batches) {
  5. t.equal(batch.state, states.shift());
  6. t.ok(batch.getCurState().name(i18n));
  7. }
  8. };
  9. const batch = init.getRecordBatch();
  10. const dataFile = path.resolve(process.cwd(), "testData", "default.json");
  11. const getBatches = (callback) => {
  12. RecordImport.find({}, "", {}, (err, batches) => {
  13. callback(null, batches.filter((batch) => (batch.state !== "error" &&
  14. batch.state !== "completed")));
  15. });
  16. };
  17. mockFS((callback) => {
  18. batch.setResults([fs.createReadStream(dataFile)], (err) => {
  19. t.error(err, "Error should be empty.");
  20. t.equal(batch.results.length, 6, "Check number of results");
  21. for (const result of batch.results) {
  22. t.equal(result.result, "unknown");
  23. t.ok(result.data);
  24. t.equal(result.data.lang, "en");
  25. }
  26. getBatches((err, batches) => {
  27. checkStates(batches, ["started"]);
  28. RecordImport.advance((err) => {
  29. t.error(err, "Error should be empty.");
  30. getBatches((err, batches) => {
  31. checkStates(batches, ["process.completed"]);
  32. // Need to manually move to the next step
  33. batch.importRecords((err) => {
  34. t.error(err, "Error should be empty.");
  35. getBatches((err, batches) => {
  36. checkStates(batches, ["import.completed"]);
  37. RecordImport.advance((err) => {
  38. t.error(err, "Error should be empty.");
  39. getBatches((err, batches) => {
  40. checkStates(batches,
  41. ["similarity.sync.completed"]);
  42. RecordImport.advance((err) => {
  43. t.error(err,
  44. "Error should be empty.");
  45. t.ok(batch.getCurState()
  46. .name(i18n));
  47. getBatches((err, batches) => {
  48. checkStates(batches, []);
  49. t.end();
  50. callback();
  51. });
  52. });
  53. t.ok(batch.getCurState().name(i18n));
  54. });
  55. });
  56. t.ok(batch.getCurState().name(i18n));
  57. });
  58. });
  59. t.ok(batch.getCurState().name(i18n));
  60. });
  61. });
  62. t.ok(batch.getCurState().name(i18n));
  63. });
  64. });
  65. });
  66. });