Skip to content

Instantly share code, notes, and snippets.

@gagamil
Created January 20, 2023 08:20
Show Gist options
  • Save gagamil/63b72fd3da7378f287e96e523805b94f to your computer and use it in GitHub Desktop.
Save gagamil/63b72fd3da7378f287e96e523805b94f to your computer and use it in GitHub Desktop.
Test task CH
Ticket Breakdown
Epic: "Currently, the id of each Agent on the reports we generate is their internal database id. We'd like to add the ability for Facilities to save their own custom ids for each Agent they work with and use that id when generating reports for them."
Complexity: 1, 2, 3, 5, 8, 12...
Tasks:
1) Add table "FacilityAgents" with columns:
* agent - FK to "Agents"
* facility - FK to "Facilities"
* external_id - String (varchar)
This will be used to hold the associated data from the facilities with our agents.
Complexity - 2 (models, migration files, docs)
<backend>
2) Modify "getShiftsByFacility" - annotate shift with data from "FacilityAgents" and add this to "Agent" metadata (or better - substitute the internal id - discuss with product)
This is the point where we inject the extra data to the resulting dataset. (If the external_id is added iso being substituted then also alter the report compilation - add new column or field - one more task in this case)
Complexity - 3 (discussion with product, code, unit tests for the logic, docs)
<backend>
3) Create an endpoint to update the "FacilityAgents" table in batch per facility (batch of 1 is ok).
Endpoint URL: /api/facility/<int:facility_id>/agents/; Method:PUT; DATA: [{agent_id: <ID_VALUE>, external_id: <STRING_VALUE>}]
The logic behind e ndpoint will use the Agent internal id to create or update a row in the table. The facility Id will be available from the request route param.
Complexity - 3 (code, unit tests, docs)
<backend>
4) Create an endpoint to fetch the "FacilityAgents" list.
Endpoint URL: /api/facility/<int:facility_id>/agents/; Method:GET; Response body: [{agent_full_name: <AGENT_NAME>, agent_id: <ID_VALUE>, external_id: <STRING_VALUE>}]
Complexity - 3 (code, unit tests, docs)
<backend>
5) Create UI to add a user to "FacilityAgents" table along with the desired "external_id" feeld.
Route the page and component.
Complexity - 5 (code, tests, docs)
<frontend>
6) Create UI to see the list of facilities agents (table, header with add action -> insert row in UI)
Route the page and component.
Complexity - 5 (code, tests, docs)
Refactoring
Comment: I didn't quite get what this functions purpose is.
So guessing some of the logic here...
exports.deterministicPartitionKey = (event) => {
  const TRIVIAL_PARTITION_KEY = "0";
  const MAX_PARTITION_KEY_LENGTH = 256;
  let candidate;
  if (event) {
    if (event.partitionKey) {
      candidate = event.partitionKey;
if (typeof candidate !== "string") {
      candidate = JSON.stringify(candidate);
    }
if (candidate.length > MAX_PARTITION_KEY_LENGTH) {
    candidate = crypto.createHash("sha3-512").update(candidate).digest("hex");
  }
    } else {
      const data = JSON.stringify(event);
      candidate = crypto.createHash("sha3-512").update(data).digest("hex");
    }
  }else{
candidate = TRIVIAL_PARTITION_KEY;
}
return candidate;
};
Tests (pseudo tests):
const test_partition_key_ok(){
res = deterministicPartitionKey({partitionKey:'0'})
assertTrue(candidate.length <= MAX_PARTITION_KEY_LENGTH)
}
const test_no_event_or_part_key(){
res = deterministicPartitionKey()
assertTrue(candidate.length <= MAX_PARTITION_KEY_LENGTH)
res = deterministicPartitionKey({foo:'0'})
assertTrue(candidate.length <= MAX_PARTITION_KEY_LENGTH)
}
Basically refactored this one based on some logical assumptions:
* I don't know what might the event.partitionKey type or values be
* based on the flow and more or less known types some parts of code can be localised to ease the code reading.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment