Test for fetching statuses from a selected instance

This commit is contained in:
Angelina Filippova 2020-05-12 22:43:15 +03:00
parent 8e671ac984
commit bcc1ea16ff
3 changed files with 63 additions and 6 deletions

View file

@ -6,10 +6,47 @@ export async function deleteStatus(id, authHost, token) {
return Promise.resolve()
}
export async function fetchStatusesCount(instance, authHost, token) {
const data = {
'status_visibility':
{ 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 }
}
export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) {
const data = [
{
'account': {
'avatar': 'http://localhost:4000/images/avi.png',
'display_name': 'sky',
'url': 'http://localhost:4000/users/sky'
},
'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.',
'created_at': '2020-01-31T18:20:01.000Z',
'id': '9rZIr0Jzao5Gjgfmro',
'sensitive': false,
'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98',
'visibility': 'unlisted'
},
{
'account': {
'avatar': 'http://localhost:4000/images/avi.png',
'display_name': 'sky',
'url': 'http://localhost:4000/users/sky'
},
'content': 'the happiest man ever',
'created_at': '2019-11-23T12:56:18.000Z',
'id': '9pFoVfWMU3A96Rzq3k',
'sensitive': false,
'url': 'http://localhost:4000/objects/449c90fe-c457-4c64-baf2-fe6d0a59ca25',
'visibility': 'unlisted'
}
]
return Promise.resolve({ data })
}
export async function fetchStatusesCount(instance, authHost, token) {
const data = instance === 'heaven.com'
? {
'status_visibility':
{ 'direct': 1, 'private': 2, 'public': 3, 'unlisted': 0 }
}
: {
'status_visibility':
{ 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 }
}
return Promise.resolve({ data })
}

View file

@ -38,4 +38,24 @@ describe('Statuses', () => {
expect(statusVisibilityCount.unlisted).toEqual(10)
done()
})
it('fetches statuses from selected instance and updates the count', async (done) => {
const wrapper = mount(Statuses, {
store,
localVue
})
await flushPromises()
store.dispatch('HandleFilterChange', 'heaven.com')
wrapper.vm.handleFilterChange()
await flushPromises()
const statusVisibilityCount = store.state.status.statusVisibility
expect(statusVisibilityCount.direct).toEqual(1)
expect(statusVisibilityCount.private).toEqual(2)
expect(statusVisibilityCount.public).toEqual(3)
expect(statusVisibilityCount.unlisted).toEqual(0)
expect(store.state.status.fetchedStatuses.length).toEqual(2)
done()
})
})

View file

@ -11,7 +11,7 @@ export default {
peers,
settings,
status,
user
user: { ...user, state: { ...user.state, authHost: 'localhost:4000' }}
},
getters
}