chore: add test for breaching transfer limit (#2620)
This commit is contained in:
@@ -112,7 +112,7 @@ describe('files', function () {
|
|||||||
it('should encrypt and upload small file', async function () {
|
it('should encrypt and upload small file', async function () {
|
||||||
await setup({ fakeCrypto: false, subscription: true })
|
await setup({ fakeCrypto: false, subscription: true })
|
||||||
|
|
||||||
const response = await fetch('/packages/snjs/mocha/assets/small_file.md')
|
const response = await fetch('/mocha/assets/small_file.md')
|
||||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||||
|
|
||||||
const file = await Files.uploadFile(fileService, buffer, 'my-file', 'md', 1000)
|
const file = await Files.uploadFile(fileService, buffer, 'my-file', 'md', 1000)
|
||||||
@@ -125,7 +125,7 @@ describe('files', function () {
|
|||||||
it('should encrypt and upload big file', async function () {
|
it('should encrypt and upload big file', async function () {
|
||||||
await setup({ fakeCrypto: false, subscription: true })
|
await setup({ fakeCrypto: false, subscription: true })
|
||||||
|
|
||||||
const response = await fetch('/packages/snjs/mocha/assets/two_mb_file.md')
|
const response = await fetch('/mocha/assets/two_mb_file.md')
|
||||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||||
|
|
||||||
const file = await Files.uploadFile(fileService, buffer, 'my-file', 'md', 100000)
|
const file = await Files.uploadFile(fileService, buffer, 'my-file', 'md', 100000)
|
||||||
@@ -138,7 +138,7 @@ describe('files', function () {
|
|||||||
it('should delete file', async function () {
|
it('should delete file', async function () {
|
||||||
await setup({ fakeCrypto: false, subscription: true })
|
await setup({ fakeCrypto: false, subscription: true })
|
||||||
|
|
||||||
const response = await fetch('/packages/snjs/mocha/assets/small_file.md')
|
const response = await fetch('/mocha/assets/small_file.md')
|
||||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||||
|
|
||||||
const file = await Files.uploadFile(fileService, buffer, 'my-file', 'md', 1000)
|
const file = await Files.uploadFile(fileService, buffer, 'my-file', 'md', 1000)
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ describe('settings service', function () {
|
|||||||
|
|
||||||
await context.activatePaidSubscriptionForUser()
|
await context.activatePaidSubscriptionForUser()
|
||||||
|
|
||||||
const response = await fetch('/packages/snjs/mocha/assets/small_file.md')
|
const response = await fetch('/mocha/assets/small_file.md')
|
||||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||||
|
|
||||||
await Files.uploadFile(application.files, buffer, 'my-file', 'md', 1000)
|
await Files.uploadFile(application.files, buffer, 'my-file', 'md', 1000)
|
||||||
@@ -161,7 +161,7 @@ describe('settings service', function () {
|
|||||||
const usedSettingBefore = await application.settings.getSubscriptionSetting(
|
const usedSettingBefore = await application.settings.getSubscriptionSetting(
|
||||||
SettingName.create(SettingName.NAMES.FileUploadBytesUsed).getValue(),
|
SettingName.create(SettingName.NAMES.FileUploadBytesUsed).getValue(),
|
||||||
)
|
)
|
||||||
expect(usedSettingBefore).to.equal('196')
|
expect(usedSettingBefore).to.equal('1374')
|
||||||
|
|
||||||
await context.activatePaidSubscriptionForUser({
|
await context.activatePaidSubscriptionForUser({
|
||||||
cancelPreviousSubscription: true,
|
cancelPreviousSubscription: true,
|
||||||
@@ -181,7 +181,7 @@ describe('settings service', function () {
|
|||||||
)
|
)
|
||||||
expect(usedSettingAfter).to.equal(usedSettingBefore)
|
expect(usedSettingAfter).to.equal(usedSettingBefore)
|
||||||
|
|
||||||
const afterResponse = await fetch('/packages/snjs/mocha/assets/small_file.md')
|
const afterResponse = await fetch('/mocha/assets/small_file.md')
|
||||||
const afterBuffer = new Uint8Array(await afterResponse.arrayBuffer())
|
const afterBuffer = new Uint8Array(await afterResponse.arrayBuffer())
|
||||||
|
|
||||||
await Files.uploadFile(application.files, afterBuffer, 'my-file', 'md', 1000)
|
await Files.uploadFile(application.files, afterBuffer, 'my-file', 'md', 1000)
|
||||||
@@ -196,6 +196,6 @@ describe('settings service', function () {
|
|||||||
const usedSettingAfterSecondUpload = await application.settings.getSubscriptionSetting(
|
const usedSettingAfterSecondUpload = await application.settings.getSubscriptionSetting(
|
||||||
SettingName.create(SettingName.NAMES.FileUploadBytesUsed).getValue(),
|
SettingName.create(SettingName.NAMES.FileUploadBytesUsed).getValue(),
|
||||||
)
|
)
|
||||||
expect(usedSettingAfterSecondUpload).to.equal('392')
|
expect(usedSettingAfterSecondUpload).to.equal('2748')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -572,6 +572,39 @@ describe('online syncing', function () {
|
|||||||
expect(rawPayloads.length).to.equal(expectedItemCount)
|
expect(rawPayloads.length).to.equal(expectedItemCount)
|
||||||
}).timeout(Factory.SixtySecondTimeout)
|
}).timeout(Factory.SixtySecondTimeout)
|
||||||
|
|
||||||
|
it('should sync all items including ones that are breaching transfer limit', async function () {
|
||||||
|
const response = await fetch('/mocha/assets/small_file.md')
|
||||||
|
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||||
|
const numberOfNotesToExceedThe1MBTransferLimit = 80
|
||||||
|
|
||||||
|
const testContext = await Factory.createAppContextWithFakeCrypto()
|
||||||
|
await testContext.launch()
|
||||||
|
await testContext.register()
|
||||||
|
const email = testContext.email
|
||||||
|
const password = testContext.password
|
||||||
|
|
||||||
|
for (let i = 0; i < numberOfNotesToExceedThe1MBTransferLimit; i++) {
|
||||||
|
await testContext.createSyncedNote(`note ${i}`, buffer.toString())
|
||||||
|
await testContext.sync()
|
||||||
|
}
|
||||||
|
await testContext.deinit()
|
||||||
|
|
||||||
|
const secondContext = await Factory.createAppContextWithFakeCrypto(Math.random(), email, password)
|
||||||
|
await secondContext.launch()
|
||||||
|
const firstSyncPromise = secondContext.awaitNextSyncEvent(SyncEvent.PaginatedSyncRequestCompleted)
|
||||||
|
await secondContext.signIn()
|
||||||
|
|
||||||
|
const firstSyncResult = await firstSyncPromise
|
||||||
|
|
||||||
|
expect(firstSyncResult.retrievedPayloads.length > 0).to.be.true
|
||||||
|
expect(firstSyncResult.retrievedPayloads.length < numberOfNotesToExceedThe1MBTransferLimit).to.be.true
|
||||||
|
expect(firstSyncResult.successResponseData.cursor_token).not.to.be.undefined
|
||||||
|
|
||||||
|
expect(secondContext.noteCount).to.equal(numberOfNotesToExceedThe1MBTransferLimit)
|
||||||
|
|
||||||
|
await secondContext.deinit()
|
||||||
|
}).timeout(Factory.SixtySecondTimeout)
|
||||||
|
|
||||||
it('syncing an item should storage it encrypted', async function () {
|
it('syncing an item should storage it encrypted', async function () {
|
||||||
const note = await Factory.createMappedNote(application)
|
const note = await Factory.createMappedNote(application)
|
||||||
await application.mutator.setItemDirty(note)
|
await application.mutator.setItemDirty(note)
|
||||||
|
|||||||
Reference in New Issue
Block a user