|
|
@ -42,7 +42,21 @@ describe('Persistence', function () { |
|
|
|
], done) |
|
|
|
], done) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('Every line represents a document', function (done) { |
|
|
|
it('Every line represents a document', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '3', nested: { today: now } }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(3) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '2', hello: 'world' }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[2], { _id: '3', nested: { today: now } }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Every line represents a document (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
@ -63,7 +77,20 @@ describe('Persistence', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('Badly formatted lines have no impact on the treated data', function (done) { |
|
|
|
it('Badly formatted lines have no impact on the treated data', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
'garbage\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '3', nested: { today: now } }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(2) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '3', nested: { today: now } }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Badly formatted lines have no impact on the treated data (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
'garbage\n' + |
|
|
|
'garbage\n' + |
|
|
@ -84,7 +111,20 @@ describe('Persistence', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('Well formatted lines that have no _id are not included in the data', function (done) { |
|
|
|
it('Well formatted lines that have no _id are not included in the data', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ nested: { today: now } }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(2) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '2', hello: 'world' }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Well formatted lines that have no _id are not included in the data (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
@ -104,7 +144,20 @@ describe('Persistence', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('If two lines concern the same doc (= same _id), the last one is the good version', function (done) { |
|
|
|
it('If two lines concern the same doc (= same _id), the last one is the good version', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '1', nested: { today: now } }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(2) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '1', nested: { today: now } }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '2', hello: 'world' }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If two lines concern the same doc (= same _id), the last one is the good version (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
@ -124,7 +177,21 @@ describe('Persistence', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('If a doc contains $$deleted: true, that means we need to remove it from the data', function (done) { |
|
|
|
it('If a doc contains $$deleted: true, that means we need to remove it from the data', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '1', $$deleted: true }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '3', today: now }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(2) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '2', hello: 'world' }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '3', today: now }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If a doc contains $$deleted: true, that means we need to remove it from the data (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
|
model.serialize({ _id: '2', hello: 'world' }) + '\n' + |
|
|
@ -145,7 +212,20 @@ describe('Persistence', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('If a doc contains $$deleted: true, no error is thrown if the doc wasnt in the list before', function (done) { |
|
|
|
it('If a doc contains $$deleted: true, no error is thrown if the doc wasnt in the list before', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '2', $$deleted: true }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '3', today: now }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(2) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '3', today: now }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If a doc contains $$deleted: true, no error is thrown if the doc wasnt in the list before (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
model.serialize({ _id: '2', $$deleted: true }) + '\n' + |
|
|
|
model.serialize({ _id: '2', $$deleted: true }) + '\n' + |
|
|
@ -165,7 +245,24 @@ describe('Persistence', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('If a doc contains $$indexCreated, no error is thrown during treatRawData and we can get the index options', function (done) { |
|
|
|
it('If a doc contains $$indexCreated, no error is thrown during treatRawData and we can get the index options', function () { |
|
|
|
|
|
|
|
const now = new Date() |
|
|
|
|
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ $$indexCreated: { fieldName: 'test', unique: true } }) + '\n' + |
|
|
|
|
|
|
|
model.serialize({ _id: '3', today: now }) |
|
|
|
|
|
|
|
const treatedData = d.persistence.treatRawData(rawData).data |
|
|
|
|
|
|
|
const indexes = d.persistence.treatRawData(rawData).indexes |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(indexes).length.should.equal(1) |
|
|
|
|
|
|
|
assert.deepStrictEqual(indexes.test, { fieldName: 'test', unique: true }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treatedData.sort(function (a, b) { return a._id - b._id }) |
|
|
|
|
|
|
|
treatedData.length.should.equal(2) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) |
|
|
|
|
|
|
|
assert.deepStrictEqual(treatedData[1], { _id: '3', today: now }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If a doc contains $$indexCreated, no error is thrown during treatRawData and we can get the index options (with stream)', function (done) { |
|
|
|
const now = new Date() |
|
|
|
const now = new Date() |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
const rawData = model.serialize({ _id: '1', a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
model.serialize({ $$indexCreated: { fieldName: 'test', unique: true } }) + '\n' + |
|
|
|
model.serialize({ $$indexCreated: { fieldName: 'test', unique: true } }) + '\n' + |
|
|
|