diff --git a/elastic/mock/structures.js b/elastic/mock/structures.js index e8ab458..7318896 100644 --- a/elastic/mock/structures.js +++ b/elastic/mock/structures.js @@ -41,6 +41,30 @@ }), ); + mock.add( + { + method: 'POST', + path: `/${config.get('indices.structures')}/_search`, + body: { + query: { + bool: { + filter: [ + { term: { codeUnite: 'umr5142' } }, + ], + }, + }, + }, + }, + () => ({ + hits: { + total: { value: 1, relation: 'eq' }, + hits: structures + .filter(({ codeUnite }) => codeUnite.toLowerCase() === 'umr5142') + .map((structure) => ({ _source: structure })), + }, + }), + ); + mock.add({ method: 'POST', path: `/${config.get('indices.structures')}/_search`, diff --git a/routes/structures/__tests__/get.test.js b/routes/structures/__tests__/get.test.js index 8a5d6c4..672b064 100644 --- a/routes/structures/__tests__/get.test.js +++ b/routes/structures/__tests__/get.test.js @@ -71,12 +71,12 @@ expect(body).toHaveProperty('message', '"size" must be less than or equal to 1000'); }); - it('#5 GET /structures?unitCode=UMR5142', async () => { + it('#5 GET /structures/UMR5142', async () => { const app = build(); const response = await app.inject({ method: 'GET', - url: '/structures?unitCode=UMR5142', + url: '/structures/UMR5142', }); const body = JSON.parse(response.body); @@ -89,4 +89,72 @@ expect(body.data[0]).toHaveProperty('intituleUnite'); expect(body.data[0].intituleUnite).toBe('Rey - Renard'); }); + + it('#6 GET /structures/UMR5142/employees', async () => { + const app = build(); + + const response = await app.inject({ + method: 'GET', + url: '/structures/UMR5142/employees', + }); + + const body = JSON.parse(response.body); + + expect(response).toHaveProperty('statusCode', 200); + expect(response).toHaveProperty('body'); + expect(body).toHaveProperty('statusCode', 200); + expect(body).toHaveProperty('data'); + expect(body.data).toHaveLength(25); + }); + + it('#7 GET /structures/UMR5142/employees?size=10', async () => { + const app = build(); + + const response = await app.inject({ + method: 'GET', + url: '/structures/UMR5142/employees?size=10', + }); + + const body = JSON.parse(response.body); + + expect(response).toHaveProperty('statusCode', 200); + expect(response).toHaveProperty('body'); + expect(body).toHaveProperty('statusCode', 200); + expect(body).toHaveProperty('data'); + expect(body.data).toHaveLength(10); + }); + + it('#8 GET /structures/UMR5142/employees?size=0', async () => { + const app = build(); + + const response = await app.inject({ + method: 'GET', + url: '/structures/UMR5142/employees?size=0', + }); + + const body = JSON.parse(response.body); + + expect(response).toHaveProperty('statusCode', 400); + expect(response).toHaveProperty('body'); + expect(body).toHaveProperty('statusCode', 400); + expect(body).toHaveProperty('error', 'Bad Request'); + expect(body).toHaveProperty('message', '"size" must be greater than or equal to 1'); + }); + + it('#9 GET /structures/UMR5142/employees?size=10000', async () => { + const app = build(); + + const response = await app.inject({ + method: 'GET', + url: '/structures/UMR5142/employees?size=10000', + }); + + const body = JSON.parse(response.body); + + expect(response).toHaveProperty('statusCode', 400); + expect(response).toHaveProperty('body'); + expect(body).toHaveProperty('statusCode', 400); + expect(body).toHaveProperty('error', 'Bad Request'); + expect(body).toHaveProperty('message', '"size" must be less than or equal to 1000'); + }); });