chore: e2e test for fetching revisions (#2480)

This commit is contained in:
Karol Sójko
2023-09-12 15:56:48 +02:00
committed by GitHub
parent 57265d1d4e
commit 43fc95a7ac
4 changed files with 46 additions and 24 deletions

View File

@@ -71,7 +71,7 @@ jobs:
github_token: ${{ secrets.CI_PAT_TOKEN }} github_token: ${{ secrets.CI_PAT_TOKEN }}
workflow_file_name: e2e-test-suite.yml workflow_file_name: e2e-test-suite.yml
wait_interval: 30 wait_interval: 30
client_payload: '{"snjs_image_tag": "${{ github.sha }}", "author": "${{ github.actor }}", "ref_name": "${{ github.ref_name }}"}' client_payload: '{"snjs_image_tag": "${{ github.sha }}", "author": "${{ github.actor }}", "ref_name": "app:${{ github.ref }}"}'
propagate_failure: true propagate_failure: true
trigger_workflow: true trigger_workflow: true
wait_workflow: true wait_workflow: true

View File

@@ -48,7 +48,7 @@ jobs:
github_token: ${{ secrets.CI_PAT_TOKEN }} github_token: ${{ secrets.CI_PAT_TOKEN }}
workflow_file_name: e2e-test-suite.yml workflow_file_name: e2e-test-suite.yml
wait_interval: 30 wait_interval: 30
client_payload: '{"snjs_image_tag": "${{ github.sha }}", "author": "${{ github.actor }}", "ref_name": "${{ github.ref_name }}"}' client_payload: '{"snjs_image_tag": "${{ github.sha }}", "author": "${{ github.actor }}", "ref_name": "app:${{ github.ref }}"}'
propagate_failure: true propagate_failure: true
trigger_workflow: true trigger_workflow: true
wait_workflow: true wait_workflow: true

View File

@@ -269,13 +269,13 @@ describe('history manager', () => {
const item = await Factory.createSyncedNote(application) const item = await Factory.createSyncedNote(application)
expect(item).to.be.ok expect(item).to.be.ok
await Factory.sleep(2 * Factory.ServerRevisionCreationDelay) await Factory.sleep(Factory.ServerRevisionCreationDelay)
const itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid }) const itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
expect(itemHistoryOrError.isFailed()).to.equal(false) expect(itemHistoryOrError.isFailed()).to.equal(false)
const itemHistory = itemHistoryOrError.getValue() const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(1) expect(itemHistory.length >= 1).to.be.true
}) })
it('should not create new revisions within the revision frequency window', async () => { it('should not create new revisions within the revision frequency window', async () => {
@@ -291,13 +291,13 @@ describe('history manager', () => {
syncOptions, syncOptions,
) )
await Factory.sleep(2 * Factory.ServerRevisionCreationDelay) await Factory.sleep(Factory.ServerRevisionCreationDelay)
const itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid }) const itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
expect(itemHistoryOrError.isFailed()).to.equal(false) expect(itemHistoryOrError.isFailed()).to.equal(false)
const itemHistory = itemHistoryOrError.getValue() const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(1)
expect(itemHistory.length >= 1).to.be.true
}) })
it('should create new revisions outside the revision frequency window', async function () { it('should create new revisions outside the revision frequency window', async function () {

View File

@@ -4,10 +4,11 @@ import * as Collaboration from '../lib/Collaboration.js'
chai.use(chaiAsPromised) chai.use(chaiAsPromised)
const expect = chai.expect const expect = chai.expect
describe.skip('shared vault revisions', function () { describe('shared vault revisions', function () {
this.timeout(Factory.TwentySecondTimeout) this.timeout(Factory.TwentySecondTimeout)
let context let context
let deinitContactContextFunction
beforeEach(async function () { beforeEach(async function () {
localStorage.clear() localStorage.clear()
@@ -20,34 +21,43 @@ describe.skip('shared vault revisions', function () {
afterEach(async function () { afterEach(async function () {
await context.deinit() await context.deinit()
if (deinitContactContextFunction) {
await deinitContactContextFunction()
}
localStorage.clear() localStorage.clear()
sinon.restore() sinon.restore()
context = undefined context = undefined
deinitContactContextFunction = undefined
}) })
it('should be able to access shared item revisions as third party user', async () => { it('should be able to access shared item revisions as third party user', async () => {
const { note, contactContext, deinitContactContext } = const { note, contactContext, deinitContactContext } =
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context) await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
deinitContactContextFunction = deinitContactContext
await Factory.sleep(Factory.ServerRevisionFrequency) await Factory.sleep(Factory.ServerRevisionFrequency)
await context.changeNoteTitleAndSync(note, 'new title 1') await context.changeNoteTitleAndSync(note, 'new title 1')
await Factory.sleep(Factory.ServerRevisionFrequency) await Factory.sleep(Factory.ServerRevisionFrequency)
await context.changeNoteTitleAndSync(note, 'new title 2') await context.changeNoteTitleAndSync(note, 'new title 2')
await Factory.sleep(Factory.ServerRevisionCreationDelay) await Factory.sleep(Factory.ServerRevisionCreationDelay)
const itemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid }) const contactItemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid })
const itemHistory = itemHistoryOrError.getValue() const contactItemHistory = contactItemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(3) expect(contactItemHistory.length >= 2).to.be.true
await deinitContactContext() const itemHistoryOrError = await context.application.listRevisions.execute({ itemUuid: note.uuid })
const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length >= 2).to.be.true
}) })
it('should create revision if other vault member edits node', async () => { it('should create revision if other vault member edits node', async () => {
const { note, contactContext, deinitContactContext } = const { note, contactContext, deinitContactContext } =
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context) await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
deinitContactContextFunction = deinitContactContext
await Factory.sleep(Factory.ServerRevisionFrequency) await Factory.sleep(Factory.ServerRevisionFrequency)
@@ -58,14 +68,13 @@ describe.skip('shared vault revisions', function () {
const itemHistoryOrError = await context.application.listRevisions.execute({ itemUuid: note.uuid }) const itemHistoryOrError = await context.application.listRevisions.execute({ itemUuid: note.uuid })
const itemHistory = itemHistoryOrError.getValue() const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(2) expect(itemHistory.length >= 2).to.be.true
await deinitContactContext()
}) })
it('should be able to decrypt revisions as third party user', async () => { it('should be able to decrypt revisions as third party user', async () => {
const { note, contactContext, deinitContactContext } = const { note, contactContext, deinitContactContext } =
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context) await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
deinitContactContextFunction = deinitContactContext
await Factory.sleep(Factory.ServerRevisionFrequency) await Factory.sleep(Factory.ServerRevisionFrequency)
await context.changeNoteTitleAndSync(note, 'new title 1') await context.changeNoteTitleAndSync(note, 'new title 1')
@@ -83,41 +92,54 @@ describe.skip('shared vault revisions', function () {
const fetched = fetchedOrError.getValue() const fetched = fetchedOrError.getValue()
expect(fetched.payload.errorDecrypting).to.not.be.ok expect(fetched.payload.errorDecrypting).to.not.be.ok
expect(fetched.payload.content.title).to.equal('new title 1') expect(fetched.payload.content.title).to.equal('new title 1')
await deinitContactContext()
}) })
it('should not be able to access history of item removed from vault', async () => { it('should not be able to access history of item removed from vault', async () => {
const { note, contactContext, deinitContactContext } = const { note, contactContext, deinitContactContext } =
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context) await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
deinitContactContextFunction = deinitContactContext
await Factory.sleep(Factory.ServerRevisionFrequency) await Factory.sleep(Factory.ServerRevisionFrequency)
await context.changeNoteTitleAndSync(note, 'new title 1') await context.changeNoteTitleAndSync(note, 'new title 1')
await Factory.sleep(Factory.ServerRevisionCreationDelay) await Factory.sleep(Factory.ServerRevisionFrequency)
await context.vaults.removeItemFromVault(note) await context.vaults.removeItemFromVault(note)
const itemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid }) await Factory.sleep(Factory.ServerRevisionCreationDelay)
expect(itemHistoryOrError.isFailed()).to.be.true
await deinitContactContext() const itemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid })
expect(itemHistoryOrError.isFailed()).to.be.false
const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(0)
}) })
it('should not be able to access history of item after user is removed from vault', async () => { it('should not be able to access history of item after user is removed from vault', async () => {
const { note, sharedVault, contactContext, deinitContactContext } = const { note, sharedVault, contactContext, deinitContactContext } =
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context) await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
deinitContactContextFunction = deinitContactContext
await Factory.sleep(Factory.ServerRevisionFrequency) await Factory.sleep(Factory.ServerRevisionFrequency)
await context.changeNoteTitleAndSync(note, 'new title 1') await context.changeNoteTitleAndSync(note, 'new title 1')
await Factory.sleep(Factory.ServerRevisionCreationDelay) await Factory.sleep(Factory.ServerRevisionCreationDelay)
let itemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid })
expect(itemHistoryOrError.isFailed()).to.be.false
let itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length >= 1).to.be.true
await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid) await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
await Factory.sleep(Factory.ServerRevisionCreationDelay)
const itemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid }) itemHistoryOrError = await contactContext.application.listRevisions.execute({ itemUuid: note.uuid })
expect(itemHistoryOrError.isFailed()).to.be.true expect(itemHistoryOrError.isFailed()).to.be.false
itemHistory = itemHistoryOrError.getValue()
await deinitContactContext() expect(itemHistory.length).to.equal(0)
}) })
}) })