Created
April 15, 2017 01:43
-
-
Save jeresig/11002bba056f2dc9ccc64577b4814ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tap.test("RecordImport.advance", (t) => { | |
const checkStates = (batches, states) => { | |
t.equal(batches.length, states.length); | |
for (const batch of batches) { | |
t.equal(batch.state, states.shift()); | |
t.ok(batch.getCurState().name(i18n)); | |
} | |
}; | |
const batch = init.getRecordBatch(); | |
const dataFile = path.resolve(process.cwd(), "testData", "default.json"); | |
const getBatches = (callback) => { | |
RecordImport.find({}, "", {}, (err, batches) => { | |
callback(null, batches.filter((batch) => (batch.state !== "error" && | |
batch.state !== "completed"))); | |
}); | |
}; | |
mockFS((callback) => { | |
batch.setResults([fs.createReadStream(dataFile)], (err) => { | |
t.error(err, "Error should be empty."); | |
t.equal(batch.results.length, 6, "Check number of results"); | |
for (const result of batch.results) { | |
t.equal(result.result, "unknown"); | |
t.ok(result.data); | |
t.equal(result.data.lang, "en"); | |
} | |
getBatches((err, batches) => { | |
checkStates(batches, ["started"]); | |
RecordImport.advance((err) => { | |
t.error(err, "Error should be empty."); | |
getBatches((err, batches) => { | |
checkStates(batches, ["process.completed"]); | |
// Need to manually move to the next step | |
batch.importRecords((err) => { | |
t.error(err, "Error should be empty."); | |
getBatches((err, batches) => { | |
checkStates(batches, ["import.completed"]); | |
RecordImport.advance((err) => { | |
t.error(err, "Error should be empty."); | |
getBatches((err, batches) => { | |
checkStates(batches, | |
["similarity.sync.completed"]); | |
RecordImport.advance((err) => { | |
t.error(err, | |
"Error should be empty."); | |
t.ok(batch.getCurState() | |
.name(i18n)); | |
getBatches((err, batches) => { | |
checkStates(batches, []); | |
t.end(); | |
callback(); | |
}); | |
}); | |
t.ok(batch.getCurState().name(i18n)); | |
}); | |
}); | |
t.ok(batch.getCurState().name(i18n)); | |
}); | |
}); | |
t.ok(batch.getCurState().name(i18n)); | |
}); | |
}); | |
t.ok(batch.getCurState().name(i18n)); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment