This commit is contained in:
Henry Jameson 2026-08-18 03:21:11 +03:00
commit 75f9bc1775

View file

@ -57,7 +57,7 @@ describe('The users store', () => {
screen_name = userScreenName, screen_name = userScreenName,
name = userName, name = userName,
url = userUrl, url = userUrl,
id = userId id = userId,
} = {}) => ({ } = {}) => ({
id, id,
acct: screen_name, acct: screen_name,
@ -366,27 +366,45 @@ describe('The users store', () => {
describe('relationships', () => { describe('relationships', () => {
it.each(['Friends', 'Followers'])('fetch%s', async (group) => { it.each(['Friends', 'Followers'])('fetch%s', async (group) => {
const mockFetch = vi.fn() const mockFetch = vi
.fn()
.mockResolvedValueOnce( .mockResolvedValueOnce(
new Response(JSON.stringify([ new Response(
mastoApiUser({ screen_name: 'snake', name: 'John', id: '2' }), JSON.stringify([
mastoApiUser({ screen_name: 'zero', name: 'David Oh', id: '3' }), mastoApiUser({ screen_name: 'snake', name: 'John', id: '2' }),
]), { mastoApiUser({
headers: { 'Content-Type': 'application/json' }, screen_name: 'zero',
}), name: 'David Oh',
id: '3',
}),
]),
{
headers: { 'Content-Type': 'application/json' },
},
),
) )
.mockResolvedValueOnce( .mockResolvedValueOnce(
new Response(JSON.stringify([ new Response(
mastoApiUser({ screen_name: 'sigint', name: 'Mr.Anderson', id: '4' }), JSON.stringify([
mastoApiUser({ screen_name: 'paramedic', name: 'Dr.Clark', id: '5' }), mastoApiUser({
]), { screen_name: 'sigint',
headers: { 'Content-Type': 'application/json' }, name: 'Mr.Anderson',
}), id: '4',
}),
mastoApiUser({
screen_name: 'paramedic',
name: 'Dr.Clark',
id: '5',
}),
]),
{
headers: { 'Content-Type': 'application/json' },
},
),
) )
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const store = useUsersStore() const store = useUsersStore()
store.addNewUsers({ timestamp: 1, data: user() }) store.addNewUsers({ timestamp: 1, data: user() })
@ -401,7 +419,9 @@ describe('The users store', () => {
}), }),
DEFAULT_OPTIONS('GET'), DEFAULT_OPTIONS('GET'),
) )
expect(store.relationshipsLists[group.toLowerCase()].get(us)).to.have.length(2) expect(
store.relationshipsLists[group.toLowerCase()].get(us),
).to.have.length(2)
await store[`fetch${group}`](userId) await store[`fetch${group}`](userId)
expect(mockFetch).to.have.been.calledWith( expect(mockFetch).to.have.been.calledWith(
@ -412,26 +432,47 @@ describe('The users store', () => {
}), }),
DEFAULT_OPTIONS('GET'), DEFAULT_OPTIONS('GET'),
) )
expect(store.relationshipsLists[group.toLowerCase()].get(us)).to.have.length(4) expect(
store.relationshipsLists[group.toLowerCase()].get(us),
).to.have.length(4)
}) })
it.each(['Mutes', 'Blocks'])('fetch%s', async (group) => { it.each(['Mutes', 'Blocks'])('fetch%s', async (group) => {
const mockFetch = vi.fn() const mockFetch = vi
.fn()
.mockResolvedValueOnce( .mockResolvedValueOnce(
new Response(JSON.stringify([ new Response(
mastoApiUser({ screen_name: 'snake', name: 'John', id: '2' }), JSON.stringify([
mastoApiUser({ screen_name: 'zero', name: 'David Oh', id: '3' }), mastoApiUser({ screen_name: 'snake', name: 'John', id: '2' }),
]), { mastoApiUser({
headers: { 'Content-Type': 'application/json' }, screen_name: 'zero',
}), name: 'David Oh',
id: '3',
}),
]),
{
headers: { 'Content-Type': 'application/json' },
},
),
) )
.mockResolvedValueOnce( .mockResolvedValueOnce(
new Response(JSON.stringify([ new Response(
mastoApiUser({ screen_name: 'sigint', name: 'Mr.Anderson', id: '4' }), JSON.stringify([
mastoApiUser({ screen_name: 'paramedic', name: 'Dr.Clark', id: '5' }), mastoApiUser({
]), { screen_name: 'sigint',
headers: { 'Content-Type': 'application/json' }, name: 'Mr.Anderson',
}), id: '4',
}),
mastoApiUser({
screen_name: 'paramedic',
name: 'Dr.Clark',
id: '5',
}),
]),
{
headers: { 'Content-Type': 'application/json' },
},
),
) )
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
@ -464,15 +505,11 @@ describe('The users store', () => {
}) })
it('fetchDomainMutes', async () => { it('fetchDomainMutes', async () => {
const mockFetch = vi.fn() const mockFetch = vi.fn().mockResolvedValueOnce(
.mockResolvedValueOnce( new Response(JSON.stringify(['example.com', 'example.org']), {
new Response(JSON.stringify([ headers: { 'Content-Type': 'application/json' },
'example.com', }),
'example.org', )
]), {
headers: { 'Content-Type': 'application/json' },
}),
)
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
@ -489,7 +526,9 @@ describe('The users store', () => {
DEFAULT_OPTIONS('GET'), DEFAULT_OPTIONS('GET'),
) )
expect(us.domainMutes).to.have.eql(new Set(['example.com', 'example.org'])) expect(us.domainMutes).to.have.eql(
new Set(['example.com', 'example.org']),
)
}) })
it('fetchInLists', async () => { it('fetchInLists', async () => {
@ -497,12 +536,11 @@ describe('The users store', () => {
{ exclusive: false, id: '1', title: 'Operatives' }, { exclusive: false, id: '1', title: 'Operatives' },
{ exclusive: true, id: '2', title: 'Agents' }, { exclusive: true, id: '2', title: 'Agents' },
] ]
const mockFetch = vi.fn() const mockFetch = vi.fn().mockResolvedValueOnce(
.mockResolvedValueOnce( new Response(JSON.stringify(inLists), {
new Response(JSON.stringify(inLists), { headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json' }, }),
}), )
)
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
@ -513,7 +551,7 @@ describe('The users store', () => {
user(), user(),
{ ...user({ name: 'John', screen_name: 'snake', id: '2' }) }, { ...user({ name: 'John', screen_name: 'snake', id: '2' }) },
{ ...user({ name: 'David Oh', screen_name: 'zero', id: '3' }) }, { ...user({ name: 'David Oh', screen_name: 'zero', id: '3' }) },
] ],
}) })
const us = store.users.get(userId) const us = store.users.get(userId)