fix tests

This commit is contained in:
Henry Jameson 2026-02-10 21:29:48 +02:00
commit fd2986ea85
10 changed files with 199 additions and 197 deletions

View file

@ -63,6 +63,7 @@
"@babel/preset-env": "7.28.5",
"@babel/register": "7.28.3",
"@biomejs/biome": "2.3.11",
"@pinia/testing": "1.0.3",
"@ungap/event-target": "0.2.4",
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1",

View file

@ -9,8 +9,6 @@ import genRandomSeed from '../../services/random_seed/random_seed.service.js'
import EmojiPicker from '../emoji_picker/emoji_picker.vue'
import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue'
import { useEmojiStore } from 'src/stores/emoji.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faSmileBeam } from '@fortawesome/free-regular-svg-icons'
@ -133,7 +131,7 @@ const EmojiInput = {
},
computed: {
padEmoji() {
return useEmojiStore().mergedConfig.padEmoji
return this.$store.getters.mergedConfig.padEmoji
},
defaultCandidateIndex() {
return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1

View file

@ -20,8 +20,10 @@ export const getJsonOrError = async (response) => {
}
export const createApp = (instance) => {
console.log('NAP', instance)
const url = `${instance}/api/v1/apps`
const form = new window.FormData()
console.log(url)
form.append('client_name', 'PleromaFE')
form.append('website', 'https://pleroma.social')

View file

@ -83,6 +83,7 @@ export const useOAuthStore = defineStore('oauth', {
},
async getAppToken() {
const instance = useInstanceStore().server
console.log(this.clientId)
const res = await getClientToken({
clientId: this.clientId,
clientSecret: this.clientSecret,

View file

@ -1,3 +1,5 @@
import { createTestingPinia } from '@pinia/testing'
createTestingPinia()
import { createMemoryHistory, createRouter } from 'vue-router'
import { createStore } from 'vuex'

View file

@ -1,5 +1,6 @@
import { flushPromises, mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import { createTestingPinia } from '@pinia/testing'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
@ -35,6 +36,8 @@ afterEach(() => {
})
describe('Draft saving', () => {
createTestingPinia()
autoSaveOrNot(
it,
'should save when the button is clicked',

View file

@ -1,6 +1,8 @@
import { shallowMount } from '@vue/test-utils'
import vClickOutside from 'click-outside-vue3'
import { h } from 'vue'
import { createTestingPinia } from '@pinia/testing'
createTestingPinia()
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'

View file

@ -3,6 +3,8 @@ import {
mutations,
prepareStatus,
} from '../../../../src/modules/statuses.js'
import { createTestingPinia } from '@pinia/testing'
createTestingPinia()
const makeMockStatus = ({ id, text, type = 'status' }) => {
return {

View file

@ -1,7 +1,6 @@
import { HttpResponse, http } from 'msw'
import { createPinia, setActivePinia } from 'pinia'
import { createApp } from 'vue'
import { createStore } from 'vuex'
import { setActivePinia, createPinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing'
import {
authApis,
@ -10,202 +9,189 @@ import {
} from '/test/fixtures/mock_api.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useInstanceStore } from 'src/stores/instance.js'
const test = injectMswToTest(authApis)
const vuexStore = createStore({
modules: {
instance: {
state: () => ({ server: testServer }),
},
},
})
const app = createApp({})
app.use(vuexStore)
window.vuex = vuexStore
const getStore = (defaultStateInjection) => {
const pinia = createPinia().use(({ store }) => {
if (store.$id === 'oauth') {
store.$patch(defaultStateInjection)
}
})
app.use(pinia)
setActivePinia(pinia)
return useOAuthStore()
}
describe('createApp', () => {
test('it should use create an app and record client id and secret', async () => {
const store = getStore()
const app = await store.createApp()
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
expect(app.clientId).to.eql('test-id')
expect(app.clientSecret).to.eql('test-secret')
describe('oauth store', () => {
beforeEach(() => {
setActivePinia(createTestingPinia({ stubActions: false }))
useInstanceStore().server = testServer
})
test('it should throw and not update if failed', async ({ worker }) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Throttled', { status: 429 })
}),
)
describe('createApp', () => {
test('it should use create an app and record client id and secret', async () => {
const store = useOAuthStore()
const app = await store.createApp()
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
expect(app.clientId).to.eql('test-id')
expect(app.clientSecret).to.eql('test-secret')
})
const store = getStore()
const res = store.createApp()
await expect(res).rejects.toThrowError('Throttled')
expect(store.clientId).to.eql(false)
expect(store.clientSecret).to.eql(false)
})
})
describe('ensureApp', () => {
test('it should create an app if it does not exist', async () => {
const store = getStore()
const app = await store.ensureApp()
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
expect(app.clientId).to.eql('test-id')
expect(app.clientSecret).to.eql('test-secret')
})
test('it should not create an app if it exists', async ({ worker }) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Should not call this API', { status: 400 })
}),
)
const store = getStore({
clientId: 'another-id',
clientSecret: 'another-secret',
})
const app = await store.ensureApp()
expect(store.clientId).to.eql('another-id')
expect(store.clientSecret).to.eql('another-secret')
expect(app.clientId).to.eql('another-id')
expect(app.clientSecret).to.eql('another-secret')
})
})
describe('getAppToken', () => {
test('it should get app token and set it in state', async () => {
const store = getStore({
clientId: 'test-id',
clientSecret: 'test-secret',
})
const token = await store.getAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should throw and not set state if it cannot get app token', async () => {
const store = getStore({
clientId: 'bad-id',
clientSecret: 'bad-secret',
})
await expect(store.getAppToken()).rejects.toThrowError('400')
expect(store.appToken).to.eql(false)
})
})
describe('ensureAppToken', () => {
test('it should work if the state is empty', async () => {
const store = getStore()
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should work if we already have a working token', async () => {
const store = getStore({
appToken: 'also-good-app-token',
})
const token = await store.ensureAppToken()
expect(token).to.eql('also-good-app-token')
expect(store.appToken).to.eql('also-good-app-token')
})
test('it should work if we have a bad token but good app credentials', async ({
worker,
}) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Should not call this API', { status: 400 })
}),
)
const store = getStore({
appToken: 'bad-app-token',
clientId: 'test-id',
clientSecret: 'test-secret',
})
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should work if we have no token but good app credentials', async ({
worker,
}) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Should not call this API', { status: 400 })
}),
)
const store = getStore({
clientId: 'test-id',
clientSecret: 'test-secret',
})
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should work if we have no token and bad app credentials', async () => {
const store = getStore({
clientId: 'bad-id',
clientSecret: 'bad-secret',
})
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
})
test('it should work if we have bad token and bad app credentials', async () => {
const store = getStore({
appToken: 'bad-app-token',
clientId: 'bad-id',
clientSecret: 'bad-secret',
})
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
})
test('it should throw if we cannot create an app', async ({ worker }) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Throttled', { status: 429 })
}),
)
const store = getStore()
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
})
test('it should throw if we cannot obtain app token', async ({ worker }) => {
worker.use(
http.post(`${testServer}/oauth/token`, () => {
return HttpResponse.text('Throttled', { status: 429 })
}),
)
const store = getStore()
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
test('it should throw and not update if failed', async ({ worker }) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Throttled', { status: 429 })
}),
)
const store = useOAuthStore()
const res = store.createApp()
await expect(res).rejects.toThrowError('Throttled')
expect(store.clientId).to.eql(false)
expect(store.clientSecret).to.eql(false)
})
})
describe('ensureApp', () => {
test('it should create an app if it does not exist', async () => {
const store = useOAuthStore()
const app = await store.ensureApp()
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
expect(app.clientId).to.eql('test-id')
expect(app.clientSecret).to.eql('test-secret')
})
test('it should not create an app if it exists', async ({ worker }) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Should not call this API', { status: 400 })
}),
)
const store = useOAuthStore()
store.clientId = 'another-id'
store.clientSecret = 'another-secret'
const app = await store.ensureApp()
expect(store.clientId).to.eql('another-id')
expect(store.clientSecret).to.eql('another-secret')
expect(app.clientId).to.eql('another-id')
expect(app.clientSecret).to.eql('another-secret')
})
})
describe('getAppToken', () => {
test('it should get app token and set it in state', async () => {
const store = useOAuthStore()
store.clientId = 'test-id'
store.clientSecret = 'test-secret'
const token = await store.getAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should throw and not set state if it cannot get app token', async () => {
const store = useOAuthStore()
store.clientId = 'bad-id'
store.clientSecret = 'bad-secret'
await expect(store.getAppToken()).rejects.toThrowError('400')
expect(store.appToken).to.eql(false)
})
})
describe('ensureAppToken', () => {
test('it should work if the state is empty', async () => {
const store = useOAuthStore()
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should work if we already have a working token', async () => {
const store = useOAuthStore()
store.appToken = 'also-good-app-token'
const token = await store.ensureAppToken()
expect(token).to.eql('also-good-app-token')
expect(store.appToken).to.eql('also-good-app-token')
})
test('it should work if we have a bad token but good app credentials', async ({
worker,
}) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Should not call this API', { status: 400 })
}),
)
const store = useOAuthStore()
store.appToken = 'bad-app-token'
store.clientId = 'test-id'
store.clientSecret = 'test-secret'
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should work if we have no token but good app credentials', async ({
worker,
}) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Should not call this API', { status: 400 })
}),
)
const store = useOAuthStore()
store.clientId = 'test-id'
store.clientSecret = 'test-secret'
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
})
test('it should work if we have no token and bad app credentials', async () => {
const store = useOAuthStore()
store.clientId = 'bad-id'
store.clientSecret = 'bad-secret'
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
})
test('it should work if we have bad token and bad app credentials', async () => {
const store = useOAuthStore()
store.appToken = 'bad-app-token'
store.clientId = 'bad-id'
store.clientSecret = 'bad-secret'
const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token')
expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret')
})
test('it should throw if we cannot create an app', async ({ worker }) => {
worker.use(
http.post(`${testServer}/api/v1/apps`, () => {
return HttpResponse.text('Throttled', { status: 429 })
}),
)
const store = useOAuthStore()
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
})
test('it should throw if we cannot obtain app token', async ({ worker }) => {
worker.use(
http.post(`${testServer}/oauth/token`, () => {
return HttpResponse.text('Throttled', { status: 429 })
}),
)
const store = useOAuthStore()
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
})
})
})

View file

@ -2040,6 +2040,11 @@
"@parcel/watcher-win32-ia32" "2.5.1"
"@parcel/watcher-win32-x64" "2.5.1"
"@pinia/testing@1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@pinia/testing/-/testing-1.0.3.tgz#62e0813a7a8ac735505422bb7a4e38eb86f815dc"
integrity sha512-g+qR49GNdI1Z8rZxKrQC3GN+LfnGTNf5Kk8Nz5Cz6mIGva5WRS+ffPXQfzhA0nu6TveWzPNYTjGl4nJqd3Cu9Q==
"@pkgjs/parseargs@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"