fix tests. msw has issues on firefox with vitest isolation.

This commit is contained in:
Henry Jameson 2026-06-18 19:58:50 +03:00
commit 9d24782cd8
11 changed files with 592 additions and 863 deletions

View file

@ -5,7 +5,12 @@ import { paramsString, promisedRequest } from './helpers.js'
import { StatusCodeError } from 'src/services/errors/errors.js'
const REDIRECT_URI = `${window.location.origin}/oauth-callback`
const MASTODON_APP_VERIFY_URL = '/api/v1/apps/verify_credentials'
export const MASTODON_APP_VERIFY_URL = '/api/v1/apps/verify_credentials'
export const MASTODON_APP_URL = '/api/v1/apps'
export const OAUTH_TOKEN_URL = '/oauth/token'
export const OAUTH_MFA_CHALLENGE_URL = '/oauth/mfa/challenge'
export const OAUTH_REVOKE_URL = '/oauth/revoke'
export const createApp = () => {
const formData = new window.FormData()
@ -16,8 +21,8 @@ export const createApp = () => {
formData.append('scopes', 'read write follow push admin')
return promisedRequest({
url: '/api/v1/apps',
method: 'POST',
url: MASTODON_APP_URL,
formData,
}).then(({ data, ...rest }) => ({
...rest,
@ -61,7 +66,7 @@ export const getTokenWithCredentials = ({
formData.append('password', password)
return promisedRequest({
url: '/oauth/token',
url: OAUTH_TOKEN_URL,
method: 'POST',
formData,
})
@ -77,7 +82,7 @@ export const getToken = ({ clientId, clientSecret, code }) => {
formData.append('redirect_uri', `${window.location.origin}/oauth-callback`)
return promisedRequest({
url: '/oauth/token',
url: OAUTH_TOKEN_URL,
method: 'POST',
formData,
})
@ -92,7 +97,7 @@ export const getClientToken = ({ clientId, clientSecret }) => {
formData.append('redirect_uri', `${window.location.origin}/oauth-callback`)
return promisedRequest({
url: '/oauth/token',
url: OAUTH_TOKEN_URL,
method: 'POST',
formData,
})
@ -108,7 +113,7 @@ export const verifyOTPCode = ({ app, mfaToken, code }) => {
formData.append('challenge_type', 'totp')
return promisedRequest({
url: '/oauth/mfa/challenge',
url: OAUTH_MFA_CHALLENGE_URL,
method: 'POST',
formData,
})
@ -124,7 +129,7 @@ export const verifyRecoveryCode = ({ app, mfaToken, code }) => {
formData.append('challenge_type', 'recovery')
return promisedRequest({
url: '/oauth/mfa/challenge',
url: OAUTH_MFA_CHALLENGE_URL,
method: 'POST',
formData,
})
@ -138,7 +143,7 @@ export const revokeToken = ({ app, token }) => {
formData.append('token', token)
return promisedRequest({
url: '/oauth/revoke',
url: OAUTH_REVOKE_URL,
method: 'POST',
formData,
})

View file

@ -44,8 +44,8 @@ const MASTODON_DENY_USER_URL = (id) => `/api/v1/follow_requests/${id}/reject`
const MASTODON_USER_RELATIONSHIPS_URL = ({ id, withSuspended }) =>
`/api/v1/accounts/relationships/${paramsString({ id, withSuspended })}`
const MASTODON_USER_IN_LISTS = (id) => `/api/v1/accounts/${id}/lists`
const MASTODON_LIST_URL = (id) => `/api/v1/lists/${id}`
const MASTODON_LIST_ACCOUNTS_URL = (id) => `/api/v1/lists/${id}/accounts`
export const MASTODON_LIST_URL = (id) => `/api/v1/lists/${id}`
export const MASTODON_LIST_ACCOUNTS_URL = (id) => `/api/v1/lists/${id}/accounts`
const MASTODON_USER_BLOCKS_URL = ({
maxId,
sinceId,
@ -80,7 +80,6 @@ const MASTODON_UNPIN_OWN_STATUS = (id) => `/api/v1/statuses/${id}/unpin`
const MASTODON_MUTE_CONVERSATION = (id) => `/api/v1/statuses/${id}/mute`
const MASTODON_UNMUTE_CONVERSATION = (id) => `/api/v1/statuses/${id}/unmute`
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
const MASTODON_LISTS_URL = '/api/v1/lists'
const MASTODON_ANNOUNCEMENTS_URL = '/api/v1/announcements'
const MASTODON_ANNOUNCEMENTS_DISMISS_URL = (id) =>
`/api/v1/announcements/${id}/dismiss`
@ -824,13 +823,13 @@ export const revokeOAuthToken = ({ id, credentials }) =>
// #Lists
export const fetchLists = ({ credentials }) =>
promisedRequest({
url: MASTODON_LISTS_URL,
url: MASTODON_LIST_URL(),
credentials,
})
export const createList = ({ title, credentials }) =>
promisedRequest({
url: MASTODON_LISTS_URL,
url: MASTODON_LIST_URL(),
credentials,
method: 'POST',
payload: { title },
@ -843,6 +842,7 @@ export const getList = ({ listId, credentials }) =>
})
export const updateList = ({ listId, title, credentials }) =>
console.log('PUT', MASTODON_LIST_URL(listId)) ||
promisedRequest({
url: MASTODON_LIST_URL(listId),

View file

@ -50,8 +50,8 @@ export const useListsStore = defineStore('lists', {
setLists(value) {
this.allLists = value
},
createList({ title }) {
return createList({
async createList({ title }) {
return await createList({
title,
credentials: useOAuthStore().token,
}).then((list) => {
@ -59,14 +59,14 @@ export const useListsStore = defineStore('lists', {
return list
})
},
fetchList({ listId }) {
return getList({
async fetchList({ listId }) {
return await getList({
listId,
credentials: useOAuthStore().token,
}).then((list) => this.setList({ listId: list.id, title: list.title }))
},
fetchListAccounts({ listId }) {
return getListAccounts({
async fetchListAccounts({ listId }) {
return await getListAccounts({
listId,
credentials: useOAuthStore().token,
}).then((accountIds) => {
@ -76,8 +76,8 @@ export const useListsStore = defineStore('lists', {
this.allListsObject[listId].accountIds = accountIds
})
},
setList({ listId, title }) {
updateList({
async setList({ listId, title }) {
await updateList({
listId,
title,
credentials: useOAuthStore().token,
@ -95,7 +95,7 @@ export const useListsStore = defineStore('lists', {
entry.title = title
}
},
setListAccounts({ listId, accountIds }) {
async setListAccounts({ listId, accountIds }) {
const saved = this.allListsObject[listId]?.accountIds || []
const added = accountIds.filter((id) => !saved.includes(id))
const removed = saved.filter((id) => !accountIds.includes(id))
@ -103,23 +103,29 @@ export const useListsStore = defineStore('lists', {
this.allListsObject[listId] = { accountIds: [] }
}
this.allListsObject[listId].accountIds = accountIds
const promises = []
if (added.length > 0) {
addAccountsToList({
listId,
accountIds: added,
credentials: useOAuthStore().token,
})
promises.push(
addAccountsToList({
listId,
accountIds: added,
credentials: useOAuthStore().token,
}),
)
}
if (removed.length > 0) {
removeAccountsFromList({
listId,
accountIds: removed,
credentials: useOAuthStore().token,
})
promises.push(
removeAccountsFromList({
listId,
accountIds: removed,
credentials: useOAuthStore().token,
}),
)
}
await Promise.all(promises)
},
addListAccount({ listId, accountId }) {
return addAccountsToList({
async addListAccount({ listId, accountId }) {
return await addAccountsToList({
listId,
accountIds: [accountId],
credentials: useOAuthStore().token,
@ -131,8 +137,8 @@ export const useListsStore = defineStore('lists', {
return result
})
},
removeListAccount({ listId, accountId }) {
return removeAccountsFromList({
async removeListAccount({ listId, accountId }) {
return await removeAccountsFromList({
listId,
accountIds: [accountId],
credentials: useOAuthStore().token,
@ -148,8 +154,8 @@ export const useListsStore = defineStore('lists', {
return result
})
},
deleteList({ listId }) {
deleteList({
async deleteList({ listId }) {
await deleteList({
listId,
credentials: useOAuthStore().token,
})

View file

@ -233,9 +233,18 @@ export const _mergeJournal = (...journals) => {
Object.hasOwn(entry, 'timestamp'),
)
const grouped = groupBy(allJournals, 'path')
const trimmedGrouped = Object.entries(grouped).map(([path, journal]) => {
// side effect
journal.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
const trimmedGrouped = Object.entries(grouped).map(([path, rawJournal]) => {
const journal = rawJournal
.map((data, index) => ({ data, index }))
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
if (a.timestamp === b.timestamp) {
return ai - bi
} else {
return a.timestamp > b.timestamp ? 1 : -1
}
})
.map((x) => x.data)
console.log(journal)
if (path.startsWith('collections')) {
const lastRemoveIndex = findLastIndex(
@ -270,9 +279,16 @@ export const _mergeJournal = (...journals) => {
}
})
const flat = flatten(trimmedGrouped).sort((a, b) =>
a.timestamp > b.timestamp ? 1 : -1,
)
const flat = flatten(trimmedGrouped)
.map((data, index) => ({ data, index }))
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
if (a.timestamp === b.timestamp) {
return ai - bi
} else {
return a.timestamp > b.timestamp ? 1 : -1
}
})
.map((x) => x.data)
return take(flat, 500)
}