fix tests
This commit is contained in:
parent
b2011429c6
commit
fd2986ea85
10 changed files with 199 additions and 197 deletions
|
|
@ -63,6 +63,7 @@
|
||||||
"@babel/preset-env": "7.28.5",
|
"@babel/preset-env": "7.28.5",
|
||||||
"@babel/register": "7.28.3",
|
"@babel/register": "7.28.3",
|
||||||
"@biomejs/biome": "2.3.11",
|
"@biomejs/biome": "2.3.11",
|
||||||
|
"@pinia/testing": "1.0.3",
|
||||||
"@ungap/event-target": "0.2.4",
|
"@ungap/event-target": "0.2.4",
|
||||||
"@vitejs/plugin-vue": "^5.2.1",
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ import genRandomSeed from '../../services/random_seed/random_seed.service.js'
|
||||||
import EmojiPicker from '../emoji_picker/emoji_picker.vue'
|
import EmojiPicker from '../emoji_picker/emoji_picker.vue'
|
||||||
import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.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 { library } from '@fortawesome/fontawesome-svg-core'
|
||||||
import { faSmileBeam } from '@fortawesome/free-regular-svg-icons'
|
import { faSmileBeam } from '@fortawesome/free-regular-svg-icons'
|
||||||
|
|
||||||
|
|
@ -133,7 +131,7 @@ const EmojiInput = {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
padEmoji() {
|
padEmoji() {
|
||||||
return useEmojiStore().mergedConfig.padEmoji
|
return this.$store.getters.mergedConfig.padEmoji
|
||||||
},
|
},
|
||||||
defaultCandidateIndex() {
|
defaultCandidateIndex() {
|
||||||
return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1
|
return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@ export const getJsonOrError = async (response) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createApp = (instance) => {
|
export const createApp = (instance) => {
|
||||||
|
console.log('NAP', instance)
|
||||||
const url = `${instance}/api/v1/apps`
|
const url = `${instance}/api/v1/apps`
|
||||||
const form = new window.FormData()
|
const form = new window.FormData()
|
||||||
|
console.log(url)
|
||||||
|
|
||||||
form.append('client_name', 'PleromaFE')
|
form.append('client_name', 'PleromaFE')
|
||||||
form.append('website', 'https://pleroma.social')
|
form.append('website', 'https://pleroma.social')
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ export const useOAuthStore = defineStore('oauth', {
|
||||||
},
|
},
|
||||||
async getAppToken() {
|
async getAppToken() {
|
||||||
const instance = useInstanceStore().server
|
const instance = useInstanceStore().server
|
||||||
|
console.log(this.clientId)
|
||||||
const res = await getClientToken({
|
const res = await getClientToken({
|
||||||
clientId: this.clientId,
|
clientId: this.clientId,
|
||||||
clientSecret: this.clientSecret,
|
clientSecret: this.clientSecret,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { createTestingPinia } from '@pinia/testing'
|
||||||
|
createTestingPinia()
|
||||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||||
import { createStore } from 'vuex'
|
import { createStore } from 'vuex'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { flushPromises, mount } from '@vue/test-utils'
|
import { flushPromises, mount } from '@vue/test-utils'
|
||||||
import { nextTick } from 'vue'
|
import { nextTick } from 'vue'
|
||||||
|
import { createTestingPinia } from '@pinia/testing'
|
||||||
|
|
||||||
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
|
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
|
||||||
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
|
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
|
||||||
|
|
@ -35,6 +36,8 @@ afterEach(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Draft saving', () => {
|
describe('Draft saving', () => {
|
||||||
|
createTestingPinia()
|
||||||
|
|
||||||
autoSaveOrNot(
|
autoSaveOrNot(
|
||||||
it,
|
it,
|
||||||
'should save when the button is clicked',
|
'should save when the button is clicked',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { shallowMount } from '@vue/test-utils'
|
import { shallowMount } from '@vue/test-utils'
|
||||||
import vClickOutside from 'click-outside-vue3'
|
import vClickOutside from 'click-outside-vue3'
|
||||||
import { h } from 'vue'
|
import { h } from 'vue'
|
||||||
|
import { createTestingPinia } from '@pinia/testing'
|
||||||
|
createTestingPinia()
|
||||||
|
|
||||||
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
|
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ import {
|
||||||
mutations,
|
mutations,
|
||||||
prepareStatus,
|
prepareStatus,
|
||||||
} from '../../../../src/modules/statuses.js'
|
} from '../../../../src/modules/statuses.js'
|
||||||
|
import { createTestingPinia } from '@pinia/testing'
|
||||||
|
createTestingPinia()
|
||||||
|
|
||||||
const makeMockStatus = ({ id, text, type = 'status' }) => {
|
const makeMockStatus = ({ id, text, type = 'status' }) => {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { HttpResponse, http } from 'msw'
|
import { HttpResponse, http } from 'msw'
|
||||||
import { createPinia, setActivePinia } from 'pinia'
|
import { setActivePinia, createPinia } from 'pinia'
|
||||||
import { createApp } from 'vue'
|
import { createTestingPinia } from '@pinia/testing'
|
||||||
import { createStore } from 'vuex'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
authApis,
|
authApis,
|
||||||
|
|
@ -10,202 +9,189 @@ import {
|
||||||
} from '/test/fixtures/mock_api.js'
|
} from '/test/fixtures/mock_api.js'
|
||||||
|
|
||||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||||
|
import { useInstanceStore } from 'src/stores/instance.js'
|
||||||
|
|
||||||
const test = injectMswToTest(authApis)
|
const test = injectMswToTest(authApis)
|
||||||
|
|
||||||
const vuexStore = createStore({
|
describe('oauth store', () => {
|
||||||
modules: {
|
beforeEach(() => {
|
||||||
instance: {
|
setActivePinia(createTestingPinia({ stubActions: false }))
|
||||||
state: () => ({ server: testServer }),
|
useInstanceStore().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')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it should throw and not update if failed', async ({ worker }) => {
|
describe('createApp', () => {
|
||||||
worker.use(
|
test('it should use create an app and record client id and secret', async () => {
|
||||||
http.post(`${testServer}/api/v1/apps`, () => {
|
const store = useOAuthStore()
|
||||||
return HttpResponse.text('Throttled', { status: 429 })
|
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()
|
test('it should throw and not update if failed', async ({ worker }) => {
|
||||||
const res = store.createApp()
|
worker.use(
|
||||||
await expect(res).rejects.toThrowError('Throttled')
|
http.post(`${testServer}/api/v1/apps`, () => {
|
||||||
expect(store.clientId).to.eql(false)
|
return HttpResponse.text('Throttled', { status: 429 })
|
||||||
expect(store.clientSecret).to.eql(false)
|
}),
|
||||||
})
|
)
|
||||||
})
|
|
||||||
|
const store = useOAuthStore()
|
||||||
describe('ensureApp', () => {
|
const res = store.createApp()
|
||||||
test('it should create an app if it does not exist', async () => {
|
await expect(res).rejects.toThrowError('Throttled')
|
||||||
const store = getStore()
|
expect(store.clientId).to.eql(false)
|
||||||
const app = await store.ensureApp()
|
expect(store.clientSecret).to.eql(false)
|
||||||
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('ensureApp', () => {
|
||||||
})
|
test('it should create an app if it does not exist', async () => {
|
||||||
|
const store = useOAuthStore()
|
||||||
test('it should not create an app if it exists', async ({ worker }) => {
|
const app = await store.ensureApp()
|
||||||
worker.use(
|
expect(store.clientId).to.eql('test-id')
|
||||||
http.post(`${testServer}/api/v1/apps`, () => {
|
expect(store.clientSecret).to.eql('test-secret')
|
||||||
return HttpResponse.text('Should not call this API', { status: 400 })
|
expect(app.clientId).to.eql('test-id')
|
||||||
}),
|
expect(app.clientSecret).to.eql('test-secret')
|
||||||
)
|
})
|
||||||
|
|
||||||
const store = getStore({
|
test('it should not create an app if it exists', async ({ worker }) => {
|
||||||
clientId: 'another-id',
|
worker.use(
|
||||||
clientSecret: 'another-secret',
|
http.post(`${testServer}/api/v1/apps`, () => {
|
||||||
})
|
return HttpResponse.text('Should not call this API', { status: 400 })
|
||||||
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')
|
const store = useOAuthStore()
|
||||||
})
|
store.clientId = 'another-id'
|
||||||
})
|
store.clientSecret = 'another-secret'
|
||||||
|
|
||||||
describe('getAppToken', () => {
|
const app = await store.ensureApp()
|
||||||
test('it should get app token and set it in state', async () => {
|
expect(store.clientId).to.eql('another-id')
|
||||||
const store = getStore({
|
expect(store.clientSecret).to.eql('another-secret')
|
||||||
clientId: 'test-id',
|
expect(app.clientId).to.eql('another-id')
|
||||||
clientSecret: 'test-secret',
|
expect(app.clientSecret).to.eql('another-secret')
|
||||||
})
|
})
|
||||||
const token = await store.getAppToken()
|
})
|
||||||
expect(token).to.eql('test-app-token')
|
|
||||||
expect(store.appToken).to.eql('test-app-token')
|
describe('getAppToken', () => {
|
||||||
})
|
test('it should get app token and set it in state', async () => {
|
||||||
|
const store = useOAuthStore()
|
||||||
test('it should throw and not set state if it cannot get app token', async () => {
|
store.clientId = 'test-id'
|
||||||
const store = getStore({
|
store.clientSecret = 'test-secret'
|
||||||
clientId: 'bad-id',
|
|
||||||
clientSecret: 'bad-secret',
|
const token = await store.getAppToken()
|
||||||
})
|
expect(token).to.eql('test-app-token')
|
||||||
await expect(store.getAppToken()).rejects.toThrowError('400')
|
expect(store.appToken).to.eql('test-app-token')
|
||||||
expect(store.appToken).to.eql(false)
|
})
|
||||||
})
|
|
||||||
})
|
test('it should throw and not set state if it cannot get app token', async () => {
|
||||||
|
const store = useOAuthStore()
|
||||||
describe('ensureAppToken', () => {
|
store.clientId = 'bad-id'
|
||||||
test('it should work if the state is empty', async () => {
|
store.clientSecret = 'bad-secret'
|
||||||
const store = getStore()
|
|
||||||
const token = await store.ensureAppToken()
|
await expect(store.getAppToken()).rejects.toThrowError('400')
|
||||||
expect(token).to.eql('test-app-token')
|
expect(store.appToken).to.eql(false)
|
||||||
expect(store.appToken).to.eql('test-app-token')
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it should work if we already have a working token', async () => {
|
describe('ensureAppToken', () => {
|
||||||
const store = getStore({
|
test('it should work if the state is empty', async () => {
|
||||||
appToken: 'also-good-app-token',
|
const store = useOAuthStore()
|
||||||
})
|
const token = await store.ensureAppToken()
|
||||||
const token = await store.ensureAppToken()
|
expect(token).to.eql('test-app-token')
|
||||||
expect(token).to.eql('also-good-app-token')
|
expect(store.appToken).to.eql('test-app-token')
|
||||||
expect(store.appToken).to.eql('also-good-app-token')
|
})
|
||||||
})
|
|
||||||
|
test('it should work if we already have a working token', async () => {
|
||||||
test('it should work if we have a bad token but good app credentials', async ({
|
const store = useOAuthStore()
|
||||||
worker,
|
store.appToken = 'also-good-app-token'
|
||||||
}) => {
|
|
||||||
worker.use(
|
const token = await store.ensureAppToken()
|
||||||
http.post(`${testServer}/api/v1/apps`, () => {
|
expect(token).to.eql('also-good-app-token')
|
||||||
return HttpResponse.text('Should not call this API', { status: 400 })
|
expect(store.appToken).to.eql('also-good-app-token')
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
const store = getStore({
|
test('it should work if we have a bad token but good app credentials', async ({
|
||||||
appToken: 'bad-app-token',
|
worker,
|
||||||
clientId: 'test-id',
|
}) => {
|
||||||
clientSecret: 'test-secret',
|
worker.use(
|
||||||
})
|
http.post(`${testServer}/api/v1/apps`, () => {
|
||||||
const token = await store.ensureAppToken()
|
return HttpResponse.text('Should not call this API', { status: 400 })
|
||||||
expect(token).to.eql('test-app-token')
|
}),
|
||||||
expect(store.appToken).to.eql('test-app-token')
|
)
|
||||||
})
|
const store = useOAuthStore()
|
||||||
|
store.appToken = 'bad-app-token'
|
||||||
test('it should work if we have no token but good app credentials', async ({
|
store.clientId = 'test-id'
|
||||||
worker,
|
store.clientSecret = 'test-secret'
|
||||||
}) => {
|
|
||||||
worker.use(
|
const token = await store.ensureAppToken()
|
||||||
http.post(`${testServer}/api/v1/apps`, () => {
|
expect(token).to.eql('test-app-token')
|
||||||
return HttpResponse.text('Should not call this API', { status: 400 })
|
expect(store.appToken).to.eql('test-app-token')
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
const store = getStore({
|
test('it should work if we have no token but good app credentials', async ({
|
||||||
clientId: 'test-id',
|
worker,
|
||||||
clientSecret: 'test-secret',
|
}) => {
|
||||||
})
|
worker.use(
|
||||||
const token = await store.ensureAppToken()
|
http.post(`${testServer}/api/v1/apps`, () => {
|
||||||
expect(token).to.eql('test-app-token')
|
return HttpResponse.text('Should not call this API', { status: 400 })
|
||||||
expect(store.appToken).to.eql('test-app-token')
|
}),
|
||||||
})
|
)
|
||||||
|
const store = useOAuthStore()
|
||||||
test('it should work if we have no token and bad app credentials', async () => {
|
store.clientId = 'test-id'
|
||||||
const store = getStore({
|
store.clientSecret = 'test-secret'
|
||||||
clientId: 'bad-id',
|
|
||||||
clientSecret: 'bad-secret',
|
const token = await store.ensureAppToken()
|
||||||
})
|
expect(token).to.eql('test-app-token')
|
||||||
const token = await store.ensureAppToken()
|
expect(store.appToken).to.eql('test-app-token')
|
||||||
expect(token).to.eql('test-app-token')
|
})
|
||||||
expect(store.appToken).to.eql('test-app-token')
|
|
||||||
expect(store.clientId).to.eql('test-id')
|
test('it should work if we have no token and bad app credentials', async () => {
|
||||||
expect(store.clientSecret).to.eql('test-secret')
|
const store = useOAuthStore()
|
||||||
})
|
store.clientId = 'bad-id'
|
||||||
|
store.clientSecret = 'bad-secret'
|
||||||
test('it should work if we have bad token and bad app credentials', async () => {
|
|
||||||
const store = getStore({
|
const token = await store.ensureAppToken()
|
||||||
appToken: 'bad-app-token',
|
expect(token).to.eql('test-app-token')
|
||||||
clientId: 'bad-id',
|
expect(store.appToken).to.eql('test-app-token')
|
||||||
clientSecret: 'bad-secret',
|
expect(store.clientId).to.eql('test-id')
|
||||||
})
|
expect(store.clientSecret).to.eql('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 bad token and bad app credentials', async () => {
|
||||||
expect(store.clientId).to.eql('test-id')
|
const store = useOAuthStore()
|
||||||
expect(store.clientSecret).to.eql('test-secret')
|
store.appToken = 'bad-app-token'
|
||||||
})
|
store.clientId = 'bad-id'
|
||||||
|
store.clientSecret = 'bad-secret'
|
||||||
test('it should throw if we cannot create an app', async ({ worker }) => {
|
|
||||||
worker.use(
|
const token = await store.ensureAppToken()
|
||||||
http.post(`${testServer}/api/v1/apps`, () => {
|
expect(token).to.eql('test-app-token')
|
||||||
return HttpResponse.text('Throttled', { status: 429 })
|
expect(store.appToken).to.eql('test-app-token')
|
||||||
}),
|
expect(store.clientId).to.eql('test-id')
|
||||||
)
|
expect(store.clientSecret).to.eql('test-secret')
|
||||||
|
})
|
||||||
const store = getStore()
|
|
||||||
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
|
test('it should throw if we cannot create an app', async ({ worker }) => {
|
||||||
})
|
worker.use(
|
||||||
|
http.post(`${testServer}/api/v1/apps`, () => {
|
||||||
test('it should throw if we cannot obtain app token', async ({ worker }) => {
|
return HttpResponse.text('Throttled', { status: 429 })
|
||||||
worker.use(
|
}),
|
||||||
http.post(`${testServer}/oauth/token`, () => {
|
)
|
||||||
return HttpResponse.text('Throttled', { status: 429 })
|
|
||||||
}),
|
const store = useOAuthStore()
|
||||||
)
|
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
|
||||||
|
})
|
||||||
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 = useOAuthStore()
|
||||||
|
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2040,6 +2040,11 @@
|
||||||
"@parcel/watcher-win32-ia32" "2.5.1"
|
"@parcel/watcher-win32-ia32" "2.5.1"
|
||||||
"@parcel/watcher-win32-x64" "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":
|
"@pkgjs/parseargs@^0.11.0":
|
||||||
version "0.11.0"
|
version "0.11.0"
|
||||||
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
|
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue