fix some tests
This commit is contained in:
parent
6066e80718
commit
f535a14dfc
4 changed files with 12 additions and 27 deletions
|
|
@ -69,7 +69,6 @@ export const paramsString = (params = {}) => {
|
|||
export const promisedRequest = async ({
|
||||
method,
|
||||
url,
|
||||
params,
|
||||
payload,
|
||||
formData,
|
||||
credentials,
|
||||
|
|
@ -88,17 +87,6 @@ export const promisedRequest = async ({
|
|||
options.headers['Content-Type'] = 'application/json'
|
||||
}
|
||||
|
||||
if (params) {
|
||||
url +=
|
||||
'?' +
|
||||
Object.entries(params)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
encodeURIComponent(key) + '=' + encodeURIComponent(value),
|
||||
)
|
||||
.join('&')
|
||||
}
|
||||
|
||||
if (formData || payload) {
|
||||
options.body = formData || JSON.stringify(payload)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
instance,
|
||||
})
|
||||
this.setAppToken(res.data.access_token)
|
||||
return res.access_token
|
||||
return res.data.access_token
|
||||
},
|
||||
/// Use this if you want to ensure the app is still valid to use.
|
||||
/// @return {string} The access token to the app (not attached to any user)
|
||||
|
|
|
|||
10
test/fixtures/mock_api.js
vendored
10
test/fixtures/mock_api.js
vendored
|
|
@ -2,6 +2,8 @@ import { HttpResponse, http } from 'msw'
|
|||
import { setupWorker } from 'msw/browser'
|
||||
import { test as testBase } from 'vitest'
|
||||
|
||||
export const testServer = ''
|
||||
|
||||
// https://mswjs.io/docs/recipes/vitest-browser-mode
|
||||
export const injectMswToTest = (defaultHandlers) => {
|
||||
const worker = setupWorker(...defaultHandlers)
|
||||
|
|
@ -24,16 +26,14 @@ export const injectMswToTest = (defaultHandlers) => {
|
|||
})
|
||||
}
|
||||
|
||||
export const testServer = 'https://test.server.example'
|
||||
|
||||
export const authApis = [
|
||||
http.post(`${testServer}/api/v1/apps`, () => {
|
||||
http.post('/api/v1/apps', () => {
|
||||
return HttpResponse.json({
|
||||
client_id: 'test-id',
|
||||
client_secret: 'test-secret',
|
||||
})
|
||||
}),
|
||||
http.get(`${testServer}/api/v1/apps/verify_credentials`, ({ request }) => {
|
||||
http.get('/api/v1/apps/verify_credentials', ({ request }) => {
|
||||
const authHeader = request.headers.get('Authorization')
|
||||
if (
|
||||
authHeader === 'Bearer test-app-token' ||
|
||||
|
|
@ -50,7 +50,7 @@ export const authApis = [
|
|||
)
|
||||
}
|
||||
}),
|
||||
http.post(`${testServer}/oauth/token`, async ({ request }) => {
|
||||
http.post('/oauth/token', async ({ request }) => {
|
||||
const data = await request.formData()
|
||||
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ import { createPinia, setActivePinia } from 'pinia'
|
|||
import {
|
||||
authApis,
|
||||
injectMswToTest,
|
||||
testServer,
|
||||
} from '/test/fixtures/mock_api.js'
|
||||
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
|
||||
const test = injectMswToTest(authApis)
|
||||
|
|
@ -16,7 +14,6 @@ const test = injectMswToTest(authApis)
|
|||
describe('oauth store', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createTestingPinia({ stubActions: false }))
|
||||
useInstanceStore().server = testServer
|
||||
})
|
||||
|
||||
describe('createApp', () => {
|
||||
|
|
@ -31,7 +28,7 @@ describe('oauth store', () => {
|
|||
|
||||
test('it should throw and not update if failed', async ({ worker }) => {
|
||||
worker.use(
|
||||
http.post(`${testServer}/api/v1/apps`, () => {
|
||||
http.post('/api/v1/apps', () => {
|
||||
return HttpResponse.text('Throttled', { status: 429 })
|
||||
}),
|
||||
)
|
||||
|
|
@ -56,7 +53,7 @@ describe('oauth store', () => {
|
|||
|
||||
test('it should not create an app if it exists', async ({ worker }) => {
|
||||
worker.use(
|
||||
http.post(`${testServer}/api/v1/apps`, () => {
|
||||
http.post('/api/v1/apps', () => {
|
||||
return HttpResponse.text('Should not call this API', { status: 400 })
|
||||
}),
|
||||
)
|
||||
|
|
@ -115,7 +112,7 @@ describe('oauth store', () => {
|
|||
worker,
|
||||
}) => {
|
||||
worker.use(
|
||||
http.post(`${testServer}/api/v1/apps`, () => {
|
||||
http.post('/api/v1/apps', () => {
|
||||
return HttpResponse.text('Should not call this API', { status: 400 })
|
||||
}),
|
||||
)
|
||||
|
|
@ -133,7 +130,7 @@ describe('oauth store', () => {
|
|||
worker,
|
||||
}) => {
|
||||
worker.use(
|
||||
http.post(`${testServer}/api/v1/apps`, () => {
|
||||
http.post('/api/v1/apps', () => {
|
||||
return HttpResponse.text('Should not call this API', { status: 400 })
|
||||
}),
|
||||
)
|
||||
|
|
@ -173,7 +170,7 @@ describe('oauth store', () => {
|
|||
|
||||
test('it should throw if we cannot create an app', async ({ worker }) => {
|
||||
worker.use(
|
||||
http.post(`${testServer}/api/v1/apps`, () => {
|
||||
http.post('/api/v1/apps', () => {
|
||||
return HttpResponse.text('Throttled', { status: 429 })
|
||||
}),
|
||||
)
|
||||
|
|
@ -186,7 +183,7 @@ describe('oauth store', () => {
|
|||
worker,
|
||||
}) => {
|
||||
worker.use(
|
||||
http.post(`${testServer}/oauth/token`, () => {
|
||||
http.post('/oauth/token', () => {
|
||||
return HttpResponse.text('Throttled', { status: 429 })
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue