Skip to content

Commit

Permalink
add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsojko committed Jan 11, 2024
1 parent 9bb4538 commit e485db5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface ApplicationOptionalConfiguratioOptions {
*/
webSocketUrl?: string

/**
* Amount sync calls allowed per minute.
*/
syncCallsThresholdPerMinute?: number

/**
Expand Down
1 change: 1 addition & 0 deletions packages/snjs/mocha/lib/Applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function createApplicationWithOptions({ identifier, environment, platform
defaultHost: host || Defaults.getDefaultHost(),
appVersion: Defaults.getAppVersion(),
webSocketUrl: Defaults.getDefaultWebSocketUrl(),
syncCallsThresholdPerMinute: Defaults.DEFAULT_SYNC_CALLS_THRESHOLD_PER_MINUTE,
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/snjs/mocha/lib/Defaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const DefaultServerPort = 3123

export const DEFAULT_SYNC_CALLS_THRESHOLD_PER_MINUTE = 100

export function getDefaultHost() {
return `http://localhost:${DefaultServerPort}`
}
Expand Down
17 changes: 17 additions & 0 deletions packages/snjs/mocha/sync_tests/online.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
import * as Factory from '../lib/factory.js'
import * as Utils from '../lib/Utils.js'
import * as Defaults from '../lib/Defaults.js'

chai.use(chaiAsPromised)
const expect = chai.expect
Expand Down Expand Up @@ -433,6 +434,22 @@ describe('online syncing', function () {
expect(allItems.length).to.equal(expectedItemCount)
})

it('should defer syncing if syncing is breaching the sync calls per minute threshold', async function () {
const safeGuard = application.dependencies.get(TYPES.SyncFrequencyGuard)

let syncCount = 0
while(!safeGuard.isSyncCallsThresholdReachedThisMinute()) {
await application.sync.sync({
onPresyncSave: () => {
syncCount++
}
})
}

expect(safeGuard.isSyncCallsThresholdReachedThisMinute()).to.equal(true)
expect(syncCount < Defaults.DEFAULT_SYNC_CALLS_THRESHOLD_PER_MINUTE).to.equal(true)
})

it('items that are never synced and deleted should not be uploaded to server', async function () {
const note = await Factory.createMappedNote(application)
await application.mutator.setItemDirty(note)
Expand Down

0 comments on commit e485db5

Please sign in to comment.