chore: add quota usage e2e tests (#2438)
* chore: add quota usage e2e tests * chore: add moving from shared to shared vault quota e2e test * chore: fix test suite name * chore: fix awaiting for notifications to propagate * chore: fix awaiting for notifications processing
This commit is contained in:
@@ -149,6 +149,10 @@ export class AppContext {
|
||||
return this.application.asymmetric
|
||||
}
|
||||
|
||||
get notifications() {
|
||||
return this.application.dependencies.get(TYPES.NotificationService)
|
||||
}
|
||||
|
||||
get keyPair() {
|
||||
return this.application.dependencies.get(TYPES.GetKeyPairs).execute().getValue().encryption
|
||||
}
|
||||
@@ -476,11 +480,6 @@ export class AppContext {
|
||||
})
|
||||
}
|
||||
|
||||
resolveWhenUserMessagesProcessingCompletes() {
|
||||
const objectToSpy = this.application.dependencies.get(TYPES.NotificationService)
|
||||
return this.resolveWhenAsyncFunctionCompletes(objectToSpy, 'handleReceivedNotifications')
|
||||
}
|
||||
|
||||
resolveWhenAllInboundAsymmetricMessagesAreDeleted() {
|
||||
const objectToSpy = this.application.dependencies.get(TYPES.AsymmetricMessageServer)
|
||||
return this.resolveWhenAsyncFunctionCompletes(objectToSpy, 'deleteAllInboundMessages')
|
||||
@@ -658,8 +657,8 @@ export class AppContext {
|
||||
return this.application.sessions.user.uuid
|
||||
}
|
||||
|
||||
sleep(seconds) {
|
||||
return Utils.sleep(seconds)
|
||||
sleep(seconds, reason = undefined) {
|
||||
return Utils.sleep(seconds, reason)
|
||||
}
|
||||
|
||||
anticipateConsoleError(message, _reason) {
|
||||
@@ -670,12 +669,25 @@ export class AppContext {
|
||||
return Utils.awaitPromiseOrThrow(promise, maxWait, reason)
|
||||
}
|
||||
|
||||
awaitPromiseOrDoNothing(promise, maxWait = 2.0, reason = 'Awaiting promise timed out; No description provided') {
|
||||
return Utils.awaitPromiseOrDoNothing(promise, maxWait, reason)
|
||||
}
|
||||
|
||||
async activatePaidSubscriptionForUser(options = {}) {
|
||||
const dateInAnHour = new Date()
|
||||
dateInAnHour.setHours(dateInAnHour.getHours() + 1)
|
||||
|
||||
options.expiresAt = options.expiresAt || dateInAnHour
|
||||
options.subscriptionPlanName = options.subscriptionPlanName || 'PRO_PLAN'
|
||||
let uploadBytesLimit = -1
|
||||
switch (options.subscriptionPlanName) {
|
||||
case 'PLUS_PLAN':
|
||||
uploadBytesLimit = 104_857_600
|
||||
break
|
||||
case 'PRO_PLAN':
|
||||
uploadBytesLimit = 107_374_182_400
|
||||
break
|
||||
}
|
||||
|
||||
try {
|
||||
await Events.publishMockedEvent('SUBSCRIPTION_PURCHASED', {
|
||||
@@ -694,16 +706,16 @@ export class AppContext {
|
||||
payAmount: 59.0,
|
||||
})
|
||||
|
||||
await Utils.sleep(2, 'Waiting for premium features to be activated')
|
||||
await this.sleep(2, 'Waiting for premium features to be activated')
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Mock events service not available. You are probably running a test suite for home server: ${error.message}`,
|
||||
)
|
||||
|
||||
try {
|
||||
await HomeServer.activatePremiumFeatures(this.email, options.subscriptionPlanName, options.expiresAt)
|
||||
await HomeServer.activatePremiumFeatures(this.email, options.subscriptionPlanName, options.expiresAt, uploadBytesLimit)
|
||||
|
||||
await Utils.sleep(1, 'Waiting for premium features to be activated')
|
||||
await this.sleep(1, 'Waiting for premium features to be activated')
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Home server not available. You are probably running a test suite for self hosted setup: ${error.message}`,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export async function uploadFile(fileService, buffer, name, ext, chunkSize, vault) {
|
||||
const operation = await fileService.beginNewFileUpload(buffer.byteLength, vault)
|
||||
export async function uploadFile(fileService, buffer, name, ext, chunkSize, vault, options = {}) {
|
||||
const byteLength = options.byteLengthOverwrite || buffer.byteLength
|
||||
const operation = await fileService.beginNewFileUpload(byteLength, vault)
|
||||
if (isClientDisplayableError(operation)) {
|
||||
return operation
|
||||
}
|
||||
|
||||
let chunkId = 1
|
||||
for (let i = 0; i < buffer.length; i += chunkSize) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Defaults from './Defaults.js'
|
||||
|
||||
export async function activatePremiumFeatures(username, subscriptionPlanName, endsAt) {
|
||||
export async function activatePremiumFeatures(username, subscriptionPlanName, endsAt, uploadBytesLimit) {
|
||||
await fetch(`${Defaults.getDefaultHost()}/e2e/activate-premium`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -11,6 +11,7 @@ export async function activatePremiumFeatures(username, subscriptionPlanName, en
|
||||
username,
|
||||
subscriptionPlanName,
|
||||
endsAt,
|
||||
uploadBytesLimit,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -53,3 +53,23 @@ export async function awaitPromiseOrThrow(promise, maxWait, reason) {
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
export async function awaitPromiseOrDoNothing(promise, maxWait, reason) {
|
||||
let timer = undefined
|
||||
|
||||
// Create a promise that resolves in <maxWait> milliseconds
|
||||
const timeout = new Promise((resolve, reject) => {
|
||||
timer = setTimeout(() => {
|
||||
clearTimeout(timer)
|
||||
const message = reason || `Promise timed out after ${maxWait} milliseconds: ${reason}`
|
||||
console.warn(message)
|
||||
resolve()
|
||||
}, maxWait * 1000)
|
||||
})
|
||||
|
||||
// Returns a race between our timeout and the passed in promise
|
||||
return Promise.race([promise, timeout]).then((result) => {
|
||||
clearTimeout(timer)
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,6 +34,24 @@ export class VaultsContext extends AppContext {
|
||||
await this.awaitPromiseOrThrow(promise, undefined, 'Waiting for keypair change message to process')
|
||||
}
|
||||
|
||||
async syncAndAwaitNotificationsProcessing() {
|
||||
await this.sleep(0.25, 'Waiting for notifications to propagate')
|
||||
|
||||
const promise = this.resolveWhenAsyncFunctionCompletes(this.notifications, 'handleReceivedNotifications')
|
||||
|
||||
await this.sync()
|
||||
|
||||
await this.awaitPromiseOrDoNothing(
|
||||
promise,
|
||||
0.25,
|
||||
'Waiting for notifications timed out. Notifications might have been processed in previous sync.'
|
||||
)
|
||||
|
||||
if (this.notifications['handleReceivedNotifications'].restore) {
|
||||
this.notifications['handleReceivedNotifications'].restore()
|
||||
}
|
||||
}
|
||||
|
||||
async syncAndAwaitMessageProcessing() {
|
||||
const promise = this.resolveWhenAsyncFunctionCompletes(this.asymmetric, 'handleRemoteReceivedAsymmetricMessages')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user