refactor: http service (#2233)

This commit is contained in:
Mo
2023-02-28 20:43:25 -06:00
committed by GitHub
parent 6e7618b258
commit e7f1d35341
142 changed files with 1116 additions and 1307 deletions

View File

@@ -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
})