Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): refactor sinkMain and create tests #897

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

asharonbaltazar
Copy link
Collaborator

Purpose

Improve sinkMain logic and write tests

Linked Issues to Close

https://jiraent.cms.gov/browse/OY2-31425

Approach

  • break out functionality into smaller pieces
  • rename functions and variables to better convey processes

Copy link
Contributor

github-actions bot commented Dec 4, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 73.97% 5979 / 8082
🔵 Statements 73.24% 6304 / 8607
🔵 Functions 67.3% 1770 / 2630
🔵 Branches 40.43% 1088 / 2691
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
lib/lambda/sinkChangelog.ts 0% 0% 0% 0% 9-98
lib/lambda/sinkCpocs.ts 33.33% 12.5% 50% 33.33% 17-18, 28-73
lib/lambda/sinkInsights.ts 0% 0% 0% 0% 6-44
lib/lambda/sinkLegacyInsights.ts 0% 0% 0% 0% 6-61
lib/lambda/sinkMain.test.ts 100% 100% 100% 100%
lib/lambda/sinkMain.ts 100% 100% 100% 100%
lib/lambda/sinkMainProcessors.test.ts 100% 100% 100% 100%
lib/lambda/sinkMainProcessors.ts 100% 100% 100% 100%
lib/lambda/sinkSubtypes.ts 0% 0% 0% 0% 6-55
lib/lambda/sinkTypes.ts 0% 0% 0% 0% 6-55
lib/libs/opensearch-lib.ts 0% 0% 0% 0% 15-283
lib/libs/sink-lib.test.ts 100% 100% 100% 100%
lib/libs/sink-lib.ts 100% 90.47% 100% 100%
lib/packages/shared-types/opensearch/main/transforms/changedDate.ts 100% 100% 75% 100%
lib/packages/shared-types/opensearch/main/transforms/seatool.ts 76.81% 63.2% 75.86% 80.35% 46-55, 59, 62, 65, 109, 47-55, 109
lib/packages/shared-types/seatool-tables/State_Plan.ts 100% 100% 100% 100%
lib/packages/shared-utils/decode.ts 100% 100% 50% 100%
react-app/src/features/package/package-details/appk.tsx 4.34% 0% 0% 4.34% 13-93
Generated in workflow #917 for commit 29a0540 by the Vitest Coverage Report Action

@asharonbaltazar asharonbaltazar temporarily deployed to refactor-tests-sink-app December 8, 2024 17:32 — with GitHub Actions Inactive
@asharonbaltazar asharonbaltazar temporarily deployed to refactor-tests-sink-kibana December 8, 2024 17:32 — with GitHub Actions Inactive
@asharonbaltazar asharonbaltazar temporarily deployed to refactor-tests-sink-kibana December 9, 2024 14:58 — with GitHub Actions Inactive
@asharonbaltazar asharonbaltazar temporarily deployed to refactor-tests-sink-app December 9, 2024 14:58 — with GitHub Actions Inactive
Copy link
Collaborator

@tbolt tbolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me. I think having someone with more experience/context with OS should add a final approval though.

@@ -13,18 +13,9 @@
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, I assumed we were using most of these packages.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is some great cleanup

@@ -1,14 +1,8 @@
import { Handler } from "aws-lambda";
import { KafkaRecord, opensearch } from "shared-types";
import { KafkaEvent } from "shared-types";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine this with the above import?

await handler(
{
eventSource: "SelfManagedKafka",
bootstrapServers: "b-1.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these real endpoints? lets take these out if they're not needed

cc: @13bfrancis

@@ -0,0 +1,87 @@
import { describe, it, expect, vi, afterEach } from "vitest";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we could use a function for the handler setup. Something like-

function createHandlerEvent(record) {
  return {
    eventSource: "SelfManagedKafka",
    bootstrapServers: "kafka",
    records: { [`"${record}"`]: [] },
  };
}

and then in the tests-

await handler(createHandlerEvent("aws.onemac.migration.cdc-0"), expect.anything(), vi.fn());

Copy link
Collaborator

@charmcitygavin charmcitygavin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this looks great. Some great refactoring to make it more testable, great removal of unused code and dependencies, and good tests. Like Tyler, I'll likely defer to someone with more familiarity with this part of the app for final approval, but this looks like great work to me.

kafkaRecords: KafkaRecord[],
topicPartition: string,
) => {
const officers = async (kafkaRecords: KafkaRecord[], topicPartition: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, where does this const get its name from? Is "officers" a Kafka term, or does it have a OneMAC-specific meaning?

@@ -82,17 +82,45 @@ const prettyPrintJsonInObject = (obj: any): any => {
return obj;
};

/**
* Returns the `osDomain` and `indexNamespace` env variables. Passing `baseIndex` appends the arg to the `index` variable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loving this documentation!

@@ -13,18 +13,9 @@
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is some great cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants