Skip to content

Commit

Permalink
LF-4170 modify api and tests for animal_identifier_placement
Browse files Browse the repository at this point in the history
  • Loading branch information
navDhammu committed Jun 5, 2024
1 parent ed46952 commit 8bd30a0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const animalIdentifierPlacementController = {
getAnimalIdentifierPlacements() {
return async (req, res) => {
try {
const { default_type_id } = req.query;
const { identifier_id } = req.query;
const rows = await AnimalIdentifierPlacement.query().modify((queryBuilder) => {
if (default_type_id) {
queryBuilder.where('default_type_id', default_type_id);
if (identifier_id) {
queryBuilder.where('identifier_id', identifier_id);
}
});
return res.status(200).send(rows);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/models/animalIdentifierPlacementModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class AnimalIdentifierPlacement extends baseModel {
static get jsonSchema() {
return {
type: 'object',
required: ['default_type_id', 'key'],
required: ['identifier_id', 'key'],
properties: {
id: { type: 'integer' },
default_type_id: { type: 'integer' },
identifier_id: { type: 'integer' },
key: { type: 'string' },
},
additionalProperties: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/api/tests/animal_identifier_placement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Animal Identifier Placement Tests', () => {

// GET TESTS
describe('Get animal identifier placement tests', () => {
test('All users should get identifier placements for a specific type', async () => {
test('All users should get identifier placements for a specific identifier type', async () => {
const roles = [1, 2, 3, 5];

// Create two placement options with two different default types
Expand All @@ -104,7 +104,7 @@ describe('Animal Identifier Placement Tests', () => {
const res = await getRequestAsPromise({
user_id: user.user_id,
farm_id: mainFarm.farm_id,
query_params_string: `default_type_id=${firstPlacement.default_type_id}`,
query_params_string: `identifier_id=${firstPlacement.identifier_id}`,
});

expect(res.status).toBe(200);
Expand All @@ -114,7 +114,7 @@ describe('Animal Identifier Placement Tests', () => {
}
});

test('All users should get placements for all types', async () => {
test('All users should get identifier placements for all identifier types', async () => {
const roles = [1, 2, 3, 5];

// Create two placement options with two different default types
Expand Down
8 changes: 3 additions & 5 deletions packages/api/tests/mock.factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2324,12 +2324,10 @@ async function animal_identifier_colorFactory() {
return knex('animal_identifier_color').insert({ key: faker.lorem.word() }).returning('*');
}

async function animal_identifier_placementFactory(
promisedAnimalType = default_animal_typeFactory(),
) {
const [animalType] = await promisedAnimalType;
async function animal_identifier_placementFactory() {
const [{ id: identifier_id }] = await animal_identifierFactory();
return knex('animal_identifier_placement')
.insert({ default_type_id: animalType.id, key: faker.lorem.word() })
.insert({ identifier_id, key: faker.lorem.word() })
.returning('*');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/api/tests/testEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ async function tableCleanup(knex) {
DELETE FROM "animal_batch";
DELETE FROM "animal_sex";
DELETE FROM "animal_identifier_color";
DELETE FROM "animal_identifier";
DELETE FROM "animal_identifier_placement";
DELETE FROM "animal_identifier";
DELETE FROM "animal_origin";
DELETE FROM "animal_type_use_relationship";
DELETE FROM "animal_use";
Expand Down

0 comments on commit 8bd30a0

Please sign in to comment.