test: refactor flakey test to use app context
This commit is contained in:
@@ -64,31 +64,25 @@ describe('application instances', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('changing default host should not affect already signed in accounts', async () => {
|
it('changing default host should not affect already signed in accounts', async () => {
|
||||||
/** This test will always succeed but should be observed for console exceptions */
|
const contextA = await Factory.createAppContext({
|
||||||
const app = await Factory.createAndInitializeApplication(
|
identifier: 'app',
|
||||||
'app',
|
host: Factory.getDefaultHost(),
|
||||||
Environment.Web,
|
|
||||||
Platform.MacWeb,
|
|
||||||
Factory.getDefaultHost(),
|
|
||||||
)
|
|
||||||
await Factory.registerUserToApplication({
|
|
||||||
application: app,
|
|
||||||
email: UuidGenerator.GenerateUuid(),
|
|
||||||
password: 'password',
|
|
||||||
})
|
})
|
||||||
await app.prepareForDeinit()
|
await contextA.launch()
|
||||||
await Factory.safeDeinit(app)
|
await contextA.register()
|
||||||
|
await contextA.deinit()
|
||||||
|
|
||||||
/** Recreate app with different host */
|
/** Recreate app with different host */
|
||||||
const recreatedApp = await Factory.createAndInitializeApplication(
|
const recreatedContext = await Factory.createAppContext({
|
||||||
'app',
|
identifier: 'app',
|
||||||
Environment.Web,
|
host: 'http://nonsense.host'
|
||||||
Platform.MacWeb,
|
})
|
||||||
'http://nonsense.host',
|
await recreatedContext.launch()
|
||||||
)
|
|
||||||
|
|
||||||
expect(recreatedApp.getHost()).to.not.equal('http://nonsense.host')
|
expect(recreatedContext.application.getHost()).to.not.equal('http://nonsense.host')
|
||||||
expect(recreatedApp.getHost()).to.equal(Factory.getDefaultHost())
|
expect(recreatedContext.application.getHost()).to.equal(Factory.getDefaultHost())
|
||||||
|
|
||||||
|
await recreatedContext.deinit()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('signing out application should delete snjs_version', async () => {
|
it('signing out application should delete snjs_version', async () => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import FakeWebCrypto from './fake_web_crypto.js'
|
import FakeWebCrypto from './fake_web_crypto.js'
|
||||||
import * as Applications from './Applications.js'
|
import * as Applications from './Applications.js'
|
||||||
import * as Utils from './Utils.js'
|
import * as Utils from './Utils.js'
|
||||||
|
import * as Defaults from './Defaults.js'
|
||||||
import { createNotePayload } from './Items.js'
|
import { createNotePayload } from './Items.js'
|
||||||
|
|
||||||
UuidGenerator.SetGenerator(new FakeWebCrypto().generateUUID)
|
UuidGenerator.SetGenerator(new FakeWebCrypto().generateUUID)
|
||||||
@@ -11,28 +12,13 @@ const MaximumSyncOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AppContext {
|
export class AppContext {
|
||||||
constructor({ identifier, crypto, email, password, passcode } = {}) {
|
constructor({ identifier, crypto, email, password, passcode, host } = {}) {
|
||||||
if (!identifier) {
|
this.identifier = identifier || `${Math.random()}`
|
||||||
identifier = `${Math.random()}`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!email) {
|
|
||||||
email = UuidGenerator.GenerateUuid()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!password) {
|
|
||||||
password = UuidGenerator.GenerateUuid()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!passcode) {
|
|
||||||
passcode = 'mypasscode'
|
|
||||||
}
|
|
||||||
|
|
||||||
this.identifier = identifier
|
|
||||||
this.crypto = crypto
|
this.crypto = crypto
|
||||||
this.email = email
|
this.email = email || UuidGenerator.GenerateUuid()
|
||||||
this.password = password
|
this.password = password || UuidGenerator.GenerateUuid()
|
||||||
this.passcode = passcode
|
this.passcode = passcode || 'mypasscode'
|
||||||
|
this.host = host || Defaults.getDefaultHost()
|
||||||
}
|
}
|
||||||
|
|
||||||
enableLogging() {
|
enableLogging() {
|
||||||
@@ -55,7 +41,7 @@ export class AppContext {
|
|||||||
this.identifier,
|
this.identifier,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
this.host,
|
||||||
this.crypto || new FakeWebCrypto(),
|
this.crypto || new FakeWebCrypto(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ export async function createAppContextWithRealCrypto(identifier) {
|
|||||||
return createAppContext({ identifier, crypto: new SNWebCrypto() })
|
return createAppContext({ identifier, crypto: new SNWebCrypto() })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createAppContext({ identifier, crypto, email, password } = {}) {
|
export async function createAppContext({ identifier, crypto, email, password, host } = {}) {
|
||||||
const context = new AppContext({ identifier, crypto, email, password })
|
const context = new AppContext({ identifier, crypto, email, password, host })
|
||||||
await context.initialize()
|
await context.initialize()
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user