Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor history e2e tests #2468

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 16 additions & 14 deletions packages/snjs/mocha/history.test.js
Expand Up @@ -4,7 +4,7 @@ import { createNoteParams } from './lib/Items.js'
chai.use(chaiAsPromised)
const expect = chai.expect

describe.skip('history manager', () => {
describe('history manager', () => {
const largeCharacterChange = 25

let application, history, email, password
Expand Down Expand Up @@ -265,23 +265,21 @@ describe.skip('history manager', () => {
expect(itemHistoryOrError.isFailed()).to.equal(true)
})

it('create basic history entries 2', async function () {
it('should save initial revisions on server', async () => {
const item = await Factory.createSyncedNote(application)

await Factory.sleep(Factory.ServerRevisionCreationDelay)

let itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
let itemHistory = itemHistoryOrError.getValue()
const itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
expect(itemHistoryOrError.isFailed()).to.equal(false)

/** Server history should save initial revision */
const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(1)
})

/** Sync within 5 seconds (ENV VAR dependend on self-hosted setup), should not create a new entry */
await Factory.markDirtyAndSyncItem(application, item)
itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(1)
it('should not create new revisions within the revision frequency window', async () => {
const item = await Factory.createSyncedNote(application)

/** Sync with different contents, should not create a new entry */
await application.changeAndSaveItem.execute(
item,
(mutator) => {
Expand All @@ -291,13 +289,17 @@ describe.skip('history manager', () => {
undefined,
syncOptions,
)

await Factory.sleep(Factory.ServerRevisionCreationDelay)
itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
itemHistory = itemHistoryOrError.getValue()

const itemHistoryOrError = await application.listRevisions.execute({ itemUuid: item.uuid })
expect(itemHistoryOrError.isFailed()).to.equal(false)

const itemHistory = itemHistoryOrError.getValue()
expect(itemHistory.length).to.equal(1)
})

it('returns revisions from server', async function () {
it('should create new revisions outside the revision frequency window', async function () {
let item = await Factory.createSyncedNote(application)

await Factory.sleep(Factory.ServerRevisionFrequency)
Expand Down
4 changes: 2 additions & 2 deletions packages/snjs/mocha/lib/VaultsContext.js
Expand Up @@ -35,15 +35,15 @@ export class VaultsContext extends AppContext {
}

async syncAndAwaitNotificationsProcessing() {
await this.sleep(0.25, 'Waiting for notifications to propagate')
await this.sleep(1, 'Waiting for notifications to propagate')

const promise = this.resolveWhenAsyncFunctionCompletes(this.notifications, 'handleReceivedNotifications')

await this.sync()

await this.awaitPromiseOrDoNothing(
promise,
0.25,
1,
'Waiting for notifications timed out. Notifications might have been processed in previous sync.'
)

Expand Down
4 changes: 2 additions & 2 deletions packages/snjs/mocha/lib/factory.js
Expand Up @@ -287,8 +287,8 @@ export async function storagePayloadCount(application) {
* The number of seconds between changes before a server creates a new revision.
* Controlled via docker/syncing-server-js.env
*/
export const ServerRevisionFrequency = 2.5
export const ServerRevisionCreationDelay = 2.5
export const ServerRevisionFrequency = 2.1
export const ServerRevisionCreationDelay = 1.0

export function yesterday() {
return new Date(new Date().setDate(new Date().getDate() - 1))
Expand Down