Commit 56e301e1 authored by lopze94's avatar lopze94
Browse files

Merge branch 'fix-activity-feed' into 'release-1.2.1'

Fixed activity feed on all Projects page

See merge request !185
parents ad611d3a cff32d51
Pipeline #4236 passed with stages
in 7 minutes and 11 seconds
......@@ -36,7 +36,8 @@ router.get('/locations', handlers.get_locations = async (req, res, next)=>{
router.get('/activity', handlers.get_all_activity = async (req, res, next)=>{
const db = require('../../db/v1')
const activity = await db.activity.getForAll()
const user_uuid = req.user.uuid
const activity = await db.activity.getUserProjectsActivity(user_uuid)
if(!activity) return next();
return res.json(activity)
......
......@@ -48,9 +48,10 @@ activity.create = async ({type: activity_type, user: user_uuid, task: task_uuid,
return joinjs.map(result.rows, relationMaps, 'activityMap', 'activity_')[0]
}
activity.getForAll = async () => {
activity.getUserProjectsActivity = async (user_uuid) => {
const query = {
text: 'select * from get_all_activity()'
text: 'select * from get_activity_for_user_projects($1)',
values: [user_uuid]
}
debug(query)
......
......@@ -29,11 +29,15 @@ begin
return query select * from v_activity where activity_uuid = new_activity_uuid;
end $function$;
create or replace function public.get_all_activity()
create or replace function public.get_activity_for_user_projects(_user_uuid uuid)
returns setof public.v_activity
language plpgsql
as $function$ begin
return query select * from v_activity;
return query select
v_activity.*
from v_project
left join v_activity on v_activity.activity_project_uuid = v_project.project_uuid
where member_uuid = _user_uuid;
end $function$;
create or replace function public.get_activity_for_user(_user_uuid uuid)
......@@ -55,4 +59,4 @@ create or replace function public.get_activity_for_project(_project_uuid uuid)
language plpgsql
as $function$ begin
return query select * from v_activity where activity_project_uuid = _project_uuid;
end $function$;
\ No newline at end of file
end $function$;
......@@ -44,16 +44,22 @@ describe('GET /api/v1/locations', ()=>{
})
describe('GET /api/v1/activity', ()=>{
beforeEach(()=>{
req.user = {uuid: 'user_uuid'}
})
test('200 | gets all activity for the app', async ()=>{
db.activity.getForAll = jest.fn(async ()=>['allActivity'])
db.activity.getUserProjectsActivity = jest.fn(async ()=>['allActivity'])
await expect(handlers.get_all_activity(req,res,next)).resolves.toBeUndefined()
expect(res.json).toBeCalledTimes(1)
expect(db.activity.getUserProjectsActivity).toBeCalledTimes(1)
expect(db.activity.getUserProjectsActivity).toBeCalledWith('user_uuid')
expect(res.json).toBeCalledWith(['allActivity'])
})
test('404 | calls next if activity is not found', async ()=>{
db.activity.getForAll = jest.fn(async ()=>undefined)
db.activity.getUserProjectsActivity = jest.fn(async ()=>undefined)
await expect(handlers.get_all_activity(req,res,next)).resolves.toBeUndefined()
expect(res.json).not.toBeCalled()
......@@ -62,7 +68,7 @@ describe('GET /api/v1/activity', ()=>{
test('500 | handles db.activity.getForAll throwing error', async ()=>{
const testError = new Error('test DB Error')
db.activity.getForAll = jest.fn(async ()=>{throw testError})
db.activity.getUserProjectsActivity = jest.fn(async ()=>{throw testError})
await expect(handlers.get_all_activity(req,res,next)).rejects.toEqual(testError)
expect(res.json).not.toBeCalled()
......
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