Skip to content

Commit

Permalink
fix: force fraud label single entry (#2663)
Browse files Browse the repository at this point in the history
* fix: force interoperator_fraud label

* feat: return same label on every fraud, single entry
  • Loading branch information
P3rceval authored Oct 24, 2024
1 parent 53acbdc commit 524e966
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("Carpool Label Repository", () => {
let db: DbContext;
let carpool_id: number;
const label = "test";
const another_label = "another_test_label";

const { before, after } = makeDbBeforeAfter();

Expand All @@ -21,19 +22,16 @@ describe("Carpool Label Repository", () => {
const data = await repository.register(insertableCarpool);
carpool_id = data._id;
await db.connection.getClient().query(
sql`INSERT INTO ${
raw(labelRepository.anomalyTable)
} (carpool_id, label) VALUES (${carpool_id}, ${label})`,
sql`INSERT INTO ${raw(labelRepository.anomalyTable)} (carpool_id, label) VALUES (${carpool_id}, ${label})`,
);
await db.connection.getClient().query(
sql`INSERT INTO ${
raw(labelRepository.fraudTable)
} (carpool_id, label) VALUES (${carpool_id}, ${label})`,
sql`INSERT INTO ${raw(labelRepository.fraudTable)} (carpool_id, label) VALUES (${carpool_id}, ${label})`,
);
await db.connection.getClient().query(
sql`INSERT INTO ${
raw(labelRepository.termsTable)
} (carpool_id, labels) VALUES (${carpool_id}, ${[label]})`,
sql`INSERT INTO ${raw(labelRepository.fraudTable)} (carpool_id, label) VALUES (${carpool_id},${another_label})`,
);
await db.connection.getClient().query(
sql`INSERT INTO ${raw(labelRepository.termsTable)} (carpool_id, labels) VALUES (${carpool_id}, ${[label]})`,
);
});

Expand All @@ -55,16 +53,30 @@ describe("Carpool Label Repository", () => {
}]);
});

it("Should read carpool fraud label", async () => {
it("Should read carpool fraud label and return single entry with 2 labels", async () => {
const result = await labelRepository.findFraudByOperatorJourneyId(
insertableCarpool.operator_id,
insertableCarpool.operator_journey_id,
);
assertEquals(result, [{
label,
label: "interoperator_fraud",
}]);
});

it("Should read carpool fraud label and return empty array if none", async () => {
// Arrange
await repository.register({ ...insertableCarpool, operator_journey_id: "operator_journey_id-4" });

// Act
const result = await labelRepository.findFraudByOperatorJourneyId(
insertableCarpool.operator_id,
"operator_journey_id-4",
);

// Assert
assertEquals(result, []);
});

it("Should read carpool terms label", async () => {
const result = await labelRepository.findTermsByOperatorJourneyId(
insertableCarpool.operator_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { provider } from "@/ilos/common/index.ts";
import {
PoolClient,
PostgresConnection,
} from "@/ilos/connection-postgres/index.ts";
import { PoolClient, PostgresConnection } from "@/ilos/connection-postgres/index.ts";
import sql, { raw } from "@/lib/pg/sql.ts";
import { CarpoolLabel } from "../interfaces/database/label.ts";

Expand Down Expand Up @@ -50,7 +47,10 @@ export class CarpoolLabelRepository {
AND cc.operator_journey_id = ${operator_journey_id}
`;
const result = await cclient.query(query);
return result.rows;
if (result.rowCount == 0) {
return [];
}
return [{ label: "interoperator_fraud" }];
}

async findAnomalyByOperatorJourneyId(
Expand Down

0 comments on commit 524e966

Please sign in to comment.