Commit 306ed685 authored by Nastassia Danilova's avatar Nastassia Danilova

reblogged_by, favourited_by api, getStatusLists thunk

parent 41d5760e
......@@ -58,6 +58,18 @@ const Statuses = {
url: `${STATUSES_URL}/${id}/unmute`
})
},
async favouritedBy ({ config, params: { id } }) {
return utils.request({
config,
url: `${STATUSES_URL}/${id}/favourited_by`
})
},
async rebloggedBy ({ config, params: { id } }) {
return utils.request({
config,
url: `${STATUSES_URL}/${id}/reblogged_by`
})
},
async post ({ config, params }) {
const body = createFormData(params)
......
......@@ -138,8 +138,8 @@ const statusesThunks = {
getStatusWithContext: ({ config, params }) => {
return async (dispatch, getState) => {
const result = await Promise.all([
statusesApi.get({ config, params }),
statusesApi.context({ config, params })
statusesApi.get({ config: getConfig(getState, config), params }),
statusesApi.context({ config: getConfig(getState, config), params })
]).then(res => apiErrorCatcher(res))
const status = { ...result[0].data, context: { ...result[1].data } }
......@@ -148,6 +148,23 @@ const statusesThunks = {
}
},
getStatusLists: ({ config, params }) => {
return async (dispatch, getState) => {
const result = await Promise.all([
statusesApi.favouritedBy({ config: getConfig(getState, config), params }),
statusesApi.rebloggedBy({ config: getConfig(getState, config), params })
]).then(res => apiErrorCatcher(res))
const status = {
id: params.id,
favourited_by: result[0].data,
reblogged_by: result[1].data
}
await dispatch(Statuses.actions.addStatus({ status }))
return getState()
}
},
deleteStatus: ({ config, params }) => {
return async (dispatch, getState) => {
await statusesApi.delete({ config: getConfig(getState, config), params }).then(res => apiErrorCatcher(res))
......
......@@ -114,6 +114,32 @@ describe('Statuses api', () => {
})
})
describe('/api/v1/statuses/:id/favourited_by', () => {
it('mute conversation', async () => {
const id = 1
fetch.mockImplementationOnce(fetchMocker([{ id: 1 }, { id: 2 }], {
expectedUrl: 'https://pleroma.soykaf.com/api/v1/statuses/1/favourited_by'
}))
const res = await api.statuses.favouritedBy({ config, params: { id } })
expect(res.state).toBe('ok')
expect(res.data).toEqual([{ id: 1 }, { id: 2 }])
})
})
describe('/api/v1/statuses/:id/reblogged_by', () => {
it('mute conversation', async () => {
const id = 1
fetch.mockImplementationOnce(fetchMocker([{ id: 1 }, { id: 2 }], {
expectedUrl: 'https://pleroma.soykaf.com/api/v1/statuses/1/reblogged_by'
}))
const res = await api.statuses.rebloggedBy({ config, params: { id } })
expect(res.state).toBe('ok')
expect(res.data).toEqual([{ id: 1 }, { id: 2 }])
})
})
describe('POST /api/v1/statuses', () => {
it('posts a status', async () => {
const id = 1
......
......@@ -505,6 +505,47 @@ describe('Status thunks', () => {
.toEqual({ 1: result })
})
it(`fetches a status' lists`, async () => {
const store = { state: { statuses:
{ statusesByIds: { 1: {
id: '1',
content: 'Status content',
spoiler_text: ''
} } }
} }
const favouritedByList = [{ id: 1 }, { id: 2 }]
const rebloggedByList = [{ id: 3 }, { id: 4 }]
fetch.mockReset()
fetch
.mockImplementationOnce(
fetchMocker(
favouritedByList,
{
expectedUrl: `https://pleroma.soykaf.com/api/v1/statuses/1/favourited_by`
})
)
.mockImplementationOnce(
fetchMocker(
rebloggedByList,
{
expectedUrl: `https://pleroma.soykaf.com/api/v1/statuses/1/reblogged_by`
})
)
let state = await statusesThunks.getStatusLists({ config, params: { id: '1' } })(dispatch(store), getState(store))
const result = {
id: '1',
content: 'Status content',
spoiler_text: '',
favourited_by: favouritedByList,
reblogged_by: rebloggedByList
}
expect(state.statuses.statusesByIds)
.toEqual({ 1: result })
})
it('delete status', async () => {
const status = {
id: '1',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment