feat(snjs): add revisions api v2 (#2154)
* feat(snjs): add revisions api v2 * fix(snjs): reference listing and getting revisions in specs * fix(snjs): revisions specs * fix(web): usage of revision metadata * fix(snjs): add specs for decryption revision * fix(snjs): issue with building mocked specs * fix(snjs): adjust revision creation delay
This commit is contained in:
@@ -282,21 +282,30 @@ describe('history manager', () => {
|
||||
this.payloadManager = this.application.payloadManager
|
||||
const item = await Factory.createSyncedNote(this.application)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
const itemHistory = await this.historyManager.remoteHistoryForItem(item)
|
||||
expect(itemHistory).to.be.undefined
|
||||
const itemHistoryOrError = await this.application.listRevisions.execute({ itemUuid: item.uuid })
|
||||
|
||||
expect(itemHistoryOrError.isFailed()).to.equal(false)
|
||||
expect(itemHistoryOrError.getValue().length).to.equal(0)
|
||||
})
|
||||
|
||||
it('create basic history entries 2', async function () {
|
||||
const item = await Factory.createSyncedNote(this.application)
|
||||
let itemHistory = await this.historyManager.remoteHistoryForItem(item)
|
||||
await Factory.sleep(Factory.ServerRevisionCreationDelay)
|
||||
|
||||
let itemHistoryOrError = await this.application.listRevisions.execute({ itemUuid: item.uuid })
|
||||
expect(itemHistoryOrError.isFailed()).to.equal(false)
|
||||
|
||||
let itemHistory = itemHistoryOrError.getValue()
|
||||
|
||||
/** Server history should save initial revision */
|
||||
expect(itemHistory).to.be.ok
|
||||
expect(itemHistory.length).to.equal(1)
|
||||
|
||||
/** Sync within 5 minutes, should not create a new entry */
|
||||
await Factory.markDirtyAndSyncItem(this.application, item)
|
||||
itemHistory = await this.historyManager.remoteHistoryForItem(item)
|
||||
itemHistoryOrError = await this.application.listRevisions.execute({ itemUuid: item.uuid })
|
||||
expect(itemHistoryOrError.isFailed()).to.equal(false)
|
||||
|
||||
itemHistory = itemHistoryOrError.getValue()
|
||||
expect(itemHistory.length).to.equal(1)
|
||||
|
||||
/** Sync with different contents, should not create a new entry */
|
||||
@@ -309,7 +318,10 @@ describe('history manager', () => {
|
||||
undefined,
|
||||
syncOptions,
|
||||
)
|
||||
itemHistory = await this.historyManager.remoteHistoryForItem(item)
|
||||
itemHistoryOrError = await this.application.listRevisions.execute({ itemUuid: item.uuid })
|
||||
expect(itemHistoryOrError.isFailed()).to.equal(false)
|
||||
|
||||
itemHistory = itemHistoryOrError.getValue()
|
||||
expect(itemHistory.length).to.equal(1)
|
||||
})
|
||||
|
||||
@@ -328,11 +340,19 @@ describe('history manager', () => {
|
||||
undefined,
|
||||
syncOptions,
|
||||
)
|
||||
let itemHistory = await this.historyManager.remoteHistoryForItem(item)
|
||||
await Factory.sleep(Factory.ServerRevisionCreationDelay)
|
||||
|
||||
const itemHistoryOrError = await this.application.listRevisions.execute({ itemUuid: item.uuid })
|
||||
expect(itemHistoryOrError.isFailed()).to.equal(false)
|
||||
|
||||
const itemHistory = itemHistoryOrError.getValue()
|
||||
expect(itemHistory.length).to.equal(2)
|
||||
|
||||
const oldestEntry = lastElement(itemHistory)
|
||||
let revisionFromServer = await this.historyManager.fetchRemoteRevision(item, oldestEntry)
|
||||
let revisionFromServerOrError = await this.application.getRevision.execute({ itemUuid: item.uuid, revisionUuid: oldestEntry.uuid })
|
||||
expect(revisionFromServerOrError.isFailed()).to.equal(false)
|
||||
|
||||
const revisionFromServer = revisionFromServerOrError.getValue()
|
||||
expect(revisionFromServer).to.be.ok
|
||||
|
||||
let payloadFromServer = revisionFromServer.payload
|
||||
@@ -349,9 +369,16 @@ describe('history manager', () => {
|
||||
await Factory.markDirtyAndSyncItem(this.application, note)
|
||||
const dupe = await this.application.itemManager.duplicateItem(note, true)
|
||||
await Factory.markDirtyAndSyncItem(this.application, dupe)
|
||||
await Factory.sleep(Factory.ServerRevisionCreationDelay)
|
||||
|
||||
const dupeHistory = await this.historyManager.remoteHistoryForItem(dupe)
|
||||
const dupeRevision = await this.historyManager.fetchRemoteRevision(dupe, dupeHistory[0])
|
||||
const dupeHistoryOrError = await this.application.listRevisions.execute({ itemUuid: dupe.uuid })
|
||||
expect(dupeHistoryOrError.isFailed()).to.equal(false)
|
||||
const dupeHistory = dupeHistoryOrError.getValue()
|
||||
|
||||
const dupeRevisionOrError = await this.application.getRevision.execute({ itemUuid: dupe.uuid, revisionUuid: dupeHistory[0].uuid })
|
||||
expect(dupeRevisionOrError.isFailed()).to.equal(false)
|
||||
|
||||
const dupeRevision = dupeRevisionOrError.getValue()
|
||||
expect(dupeRevision.payload.uuid).to.equal(dupe.uuid)
|
||||
})
|
||||
|
||||
@@ -376,8 +403,14 @@ describe('history manager', () => {
|
||||
await Factory.markDirtyAndSyncItem(this.application, dupe)
|
||||
|
||||
const expectedRevisions = 3
|
||||
const noteHistory = await this.historyManager.remoteHistoryForItem(note)
|
||||
const dupeHistory = await this.historyManager.remoteHistoryForItem(dupe)
|
||||
const noteHistoryOrError = await this.application.listRevisions.execute({ itemUuid: note.uuid })
|
||||
expect(noteHistoryOrError.isFailed()).to.equal(false)
|
||||
const noteHistory = noteHistoryOrError.getValue()
|
||||
|
||||
const dupeHistoryOrError = await this.application.listRevisions.execute({ itemUuid: dupe.uuid })
|
||||
expect(dupeHistoryOrError.isFailed()).to.equal(false)
|
||||
const dupeHistory = dupeHistoryOrError.getValue()
|
||||
|
||||
expect(noteHistory.length).to.equal(expectedRevisions)
|
||||
expect(dupeHistory.length).to.equal(expectedRevisions)
|
||||
})
|
||||
@@ -398,11 +431,17 @@ describe('history manager', () => {
|
||||
|
||||
const dupe = await this.application.itemManager.duplicateItem(note, true)
|
||||
await Factory.markDirtyAndSyncItem(this.application, dupe)
|
||||
const itemHistory = await this.historyManager.remoteHistoryForItem(dupe)
|
||||
const itemHistoryOrError = await this.application.listRevisions.execute({ itemUuid: dupe.uuid })
|
||||
expect(itemHistoryOrError.isFailed()).to.equal(false)
|
||||
|
||||
const itemHistory = itemHistoryOrError.getValue()
|
||||
expect(itemHistory.length).to.be.above(1)
|
||||
const oldestRevision = lastElement(itemHistory)
|
||||
|
||||
const fetched = await this.historyManager.fetchRemoteRevision(dupe, oldestRevision)
|
||||
const fetchedOrError = await this.application.getRevision.execute({ itemUuid: dupe.uuid, revisionUuid: oldestRevision.uuid })
|
||||
expect(fetchedOrError.isFailed()).to.equal(false)
|
||||
|
||||
const fetched = fetchedOrError.getValue()
|
||||
expect(fetched.payload.errorDecrypting).to.not.be.ok
|
||||
expect(fetched.payload.content.title).to.equal(changedText)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user