refactor: http service (#2233)
This commit is contained in:
@@ -68,7 +68,7 @@ describe('basic auth', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
expect(response).to.be.ok
|
||||
expect(response.error).to.not.be.ok
|
||||
expect(response.data.error).to.not.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
}).timeout(20000)
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('basic auth', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
expect(response).to.be.ok
|
||||
expect(response.error).to.not.be.ok
|
||||
expect(response.data.error).to.not.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
|
||||
let error
|
||||
@@ -110,7 +110,7 @@ describe('basic auth', function () {
|
||||
(async () => {
|
||||
const response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
expect(response).to.be.ok
|
||||
expect(response.error).to.not.be.ok
|
||||
expect(response.data.error).to.not.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
})(),
|
||||
(async () => {
|
||||
@@ -157,12 +157,12 @@ describe('basic auth', function () {
|
||||
|
||||
let response = await this.application.signIn(this.email, 'wrong password', undefined, undefined, undefined, true)
|
||||
expect(response).to.have.property('status', 401)
|
||||
expect(response.error).to.be.ok
|
||||
expect(response.data.error).to.be.ok
|
||||
|
||||
response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
|
||||
expect(response.status).to.equal(200)
|
||||
expect(response).to.not.haveOwnProperty('error')
|
||||
expect(response.data).to.not.haveOwnProperty('error')
|
||||
}).timeout(20000)
|
||||
|
||||
it('server retrieved key params should use our client inputted value for identifier', async function () {
|
||||
@@ -203,7 +203,7 @@ describe('basic auth', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const response = await this.application.signIn(uppercase, this.password, undefined, undefined, undefined, true)
|
||||
expect(response).to.be.ok
|
||||
expect(response.error).to.not.be.ok
|
||||
expect(response.data.error).to.not.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
}).timeout(20000)
|
||||
|
||||
@@ -219,7 +219,7 @@ describe('basic auth', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const response = await this.application.signIn(withspace, this.password, undefined, undefined, undefined, true)
|
||||
expect(response).to.be.ok
|
||||
expect(response.error).to.not.be.ok
|
||||
expect(response.data.error).to.not.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
}).timeout(20000)
|
||||
|
||||
@@ -228,7 +228,7 @@ describe('basic auth', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const response = await this.application.signIn(this.email, 'wrongpassword', undefined, undefined, undefined, true)
|
||||
expect(response).to.be.ok
|
||||
expect(response.error).to.be.ok
|
||||
expect(response.data.error).to.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.not.be.ok
|
||||
}).timeout(20000)
|
||||
|
||||
@@ -337,7 +337,7 @@ describe('basic auth', function () {
|
||||
const signinResponse = await this.application.signIn(this.email, newPassword, undefined, undefined, undefined, true)
|
||||
|
||||
expect(signinResponse).to.be.ok
|
||||
expect(signinResponse.error).to.not.be.ok
|
||||
expect(signinResponse.data.error).to.not.be.ok
|
||||
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
|
||||
@@ -420,7 +420,7 @@ describe('basic auth', function () {
|
||||
)
|
||||
|
||||
expect(signinResponse).to.be.ok
|
||||
expect(signinResponse.error).to.not.be.ok
|
||||
expect(signinResponse.data.error).to.not.be.ok
|
||||
expect(await this.application.protocolService.getRootKey()).to.be.ok
|
||||
}
|
||||
}).timeout(80000)
|
||||
|
||||
@@ -172,8 +172,8 @@ describe('server session', function () {
|
||||
Factory.ignoreChallenges(this.application)
|
||||
const syncResponse = await this.application.apiService.sync([])
|
||||
expect(syncResponse.status).to.equal(401)
|
||||
expect(syncResponse.error.tag).to.equal('invalid-auth')
|
||||
expect(syncResponse.error.message).to.equal('Invalid login credentials.')
|
||||
expect(syncResponse.data.error.tag).to.equal('invalid-auth')
|
||||
expect(syncResponse.data.error.message).to.equal('Invalid login credentials.')
|
||||
})
|
||||
|
||||
it('sign out request should be performed successfully and terminate session with expired access token', async function () {
|
||||
@@ -194,8 +194,8 @@ describe('server session', function () {
|
||||
Factory.ignoreChallenges(this.application)
|
||||
const syncResponse = await this.application.apiService.sync([])
|
||||
expect(syncResponse.status).to.equal(401)
|
||||
expect(syncResponse.error.tag).to.equal('invalid-auth')
|
||||
expect(syncResponse.error.message).to.equal('Invalid login credentials.')
|
||||
expect(syncResponse.data.error.tag).to.equal('invalid-auth')
|
||||
expect(syncResponse.data.error.message).to.equal('Invalid login credentials.')
|
||||
})
|
||||
|
||||
it('change email request should be successful with a valid access token', async function () {
|
||||
@@ -207,8 +207,7 @@ describe('server session', function () {
|
||||
const newEmail = UuidGenerator.GenerateUuid()
|
||||
const changeEmailResponse = await application.changeEmail(newEmail, password)
|
||||
|
||||
expect(changeEmailResponse.status).to.equal(200)
|
||||
expect(changeEmailResponse.data.user).to.be.ok
|
||||
expect(changeEmailResponse.error).to.not.be.ok
|
||||
|
||||
application = await Factory.signOutApplicationAndReturnNew(application)
|
||||
const loginResponse = await Factory.loginToApplication({
|
||||
@@ -277,8 +276,7 @@ describe('server session', function () {
|
||||
|
||||
const changePasswordResponse = await this.application.changePassword(this.password, this.newPassword)
|
||||
|
||||
expect(changePasswordResponse.status).to.equal(200)
|
||||
expect(changePasswordResponse.data.user).to.be.ok
|
||||
expect(changePasswordResponse.error).to.not.be.ok
|
||||
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const loginResponse = await Factory.loginToApplication({
|
||||
@@ -305,8 +303,7 @@ describe('server session', function () {
|
||||
|
||||
const changePasswordResponse = await this.application.changePassword(this.password, this.newPassword)
|
||||
|
||||
expect(changePasswordResponse).to.be.ok
|
||||
expect(changePasswordResponse.status).to.equal(200)
|
||||
expect(changePasswordResponse.error).to.not.be.ok
|
||||
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const loginResponse = await Factory.loginToApplication({
|
||||
@@ -393,8 +390,8 @@ describe('server session', function () {
|
||||
const refreshSessionResponse = await this.application.apiService.refreshSession()
|
||||
|
||||
expect(refreshSessionResponse.status).to.equal(400)
|
||||
expect(refreshSessionResponse.error.tag).to.equal('expired-refresh-token')
|
||||
expect(refreshSessionResponse.error.message).to.equal('The refresh token has expired.')
|
||||
expect(refreshSessionResponse.data.error.tag).to.equal('expired-refresh-token')
|
||||
expect(refreshSessionResponse.data.error.message).to.equal('The refresh token has expired.')
|
||||
|
||||
/*
|
||||
The access token and refresh token should be expired up to this point.
|
||||
@@ -403,8 +400,8 @@ describe('server session', function () {
|
||||
Factory.ignoreChallenges(this.application)
|
||||
const syncResponse = await this.application.apiService.sync([])
|
||||
expect(syncResponse.status).to.equal(401)
|
||||
expect(syncResponse.error.tag).to.equal('invalid-auth')
|
||||
expect(syncResponse.error.message).to.equal('Invalid login credentials.')
|
||||
expect(syncResponse.data.error.tag).to.equal('invalid-auth')
|
||||
expect(syncResponse.data.error.message).to.equal('Invalid login credentials.')
|
||||
})
|
||||
|
||||
it('should fail when renewing a session with an invalid refresh token', async function () {
|
||||
@@ -428,8 +425,8 @@ describe('server session', function () {
|
||||
const refreshSessionResponse = await this.application.apiService.refreshSession()
|
||||
|
||||
expect(refreshSessionResponse.status).to.equal(400)
|
||||
expect(refreshSessionResponse.error.tag).to.equal('invalid-refresh-token')
|
||||
expect(refreshSessionResponse.error.message).to.equal('The refresh token is not valid.')
|
||||
expect(refreshSessionResponse.data.error.tag).to.equal('invalid-refresh-token')
|
||||
expect(refreshSessionResponse.data.error.message).to.equal('The refresh token is not valid.')
|
||||
|
||||
// Access token should remain valid.
|
||||
const syncResponse = await this.application.apiService.sync([])
|
||||
@@ -446,10 +443,10 @@ describe('server session', function () {
|
||||
const refreshPromise = this.application.apiService.refreshSession()
|
||||
const syncResponse = await this.application.apiService.sync([])
|
||||
|
||||
expect(syncResponse.error).to.be.ok
|
||||
expect(syncResponse.data.error).to.be.ok
|
||||
|
||||
const errorMessage = 'Your account session is being renewed with the server. Please try your request again.'
|
||||
expect(syncResponse.error.message).to.be.equal(errorMessage)
|
||||
expect(syncResponse.data.error.message).to.be.equal(errorMessage)
|
||||
/** Wait for finish so that test cleans up properly */
|
||||
await refreshPromise
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user