Commit cff32d51 authored by lopze94's avatar lopze94
Browse files

Fixed sql and failed test

parent b4238b34
Pipeline #4235 passed with stage
in 2 minutes and 18 seconds
......@@ -33,9 +33,10 @@ 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 v_activity.*
return query select
v_activity.*
from v_project
left join v_activity on "v_activity".activity_project_uuid = "v_project".project_uuid
left join v_activity on v_activity.activity_project_uuid = v_project.project_uuid
where member_uuid = _user_uuid;
end $function$;
......@@ -59,16 +60,3 @@ create or replace function public.get_activity_for_project(_project_uuid uuid)
as $function$ begin
return query select * from v_activity where activity_project_uuid = _project_uuid;
end $function$;
select distinct
project_uuid,
project_name,
member_uuid,
member_firstname,
member_lastname,
member_username
from v_project
left join v_activity on v_activity.project_uuid = v_project.project_uuid
where member_uuid = '3b662379-27cd-47e7-9f90-08655c508df5' and project_deleted = false
;
......@@ -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