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

Fix: Deployed by filter capitalization #479

Merged
merged 12 commits into from
May 7, 2021

Conversation

jmoguilevsky
Copy link
Contributor

@jmoguilevsky jmoguilevsky commented May 6, 2021

This PR:

  • Introduces a new index for deployer_address for the lowercase of the column, since we'll be searching ignoring case, but saving values as they come
  • Creates a test suite for DeploymentRepository, achieving ~100% coverage mocking the database
  • Fixes a bug in the createOrClause method where the timestamp type was hardcoded and didn't change based on the filter type
  • Modifies the query for deployer_address so that it looks for the LOWER of the incoming address
  • Modifies some queries from multiline to single line to make them more testable

Fixes #291

@jmoguilevsky jmoguilevsky requested a review from agusaldasoro May 6, 2021 00:32
Copy link
Contributor

@agusaldasoro agusaldasoro left a comment

Choose a reason for hiding this comment

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

Great Work! Just a few comments, also do you mind adding an integration test that executes the same behaviour as described in the bug report?

*/

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.sql(`CREATE INDEX deployer_address_lower_case on deployments (LOWER(deployer_address) text_pattern_ops);`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we delete the original index on deployer_address ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

when(db.map(anything(), anything(), anything())).thenReturn(Promise.resolve(dbResult))
})

it('should return a map of entity id to the deployment status', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this text to reflect what you are verifying

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the correct verification, splitted the test for two different verifications

const entities = ['1', '3']
const result = await repository.areEntitiesDeployed(entities)

expect(result).toEqual(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd remove this as the only thing that you are testing is the mock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is asserting on the logic of the map creation in the return statement of the function

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad!

})
})

describe('when the entities list is empty', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't seem to add value as you are only testing the mock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is asserting on the first if of the function (

) that's why It also asserts on never called of the mock

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad!

const args = capture(db.map).last()

expect(args[0]).toContain(`ORDER BY dep1.entity_timestamp ASC`)
expect(args[0]).toContain(
Copy link
Contributor

Choose a reason for hiding this comment

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

niceeeeee 👏

describe('when it receives a lastId', () => {
const lastId = '1'

beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

As we don't really care about the response from the MockedDataBase can we configure this only once for the entire file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, but that makes the tests coupled since the mock is the same among all tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why I initialized it in each test context

})

it('should add the expected where clause to the query with the addresses on lowercase', async () => {
const deployedBy = ['jOn', 'aGus']
Copy link
Contributor

Choose a reason for hiding this comment

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

🤣

const args = capture(db.map).last()

expect(args[0]).toContain(`LOWER(dep1.deployer_address) IN ($(deployedBy:list))`)
expect(args[1]).toEqual(jasmine.objectContaining({ deployedBy: deployedBy.map((x) => x.toLowerCase()) }))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: as this is the expected param, shouldn't it be hardcoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to have it hardcoded

Copy link
Contributor

@agusaldasoro agusaldasoro left a comment

Choose a reason for hiding this comment

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

Great work, especially creating the repository tests! 👏

Just check the two comments and then you are free to merge.

}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.sql(`DROP INDEX deployer_address_lower_case;`)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are maintaining those down functions then we should create the original index here

@jmoguilevsky jmoguilevsky merged commit 638f4b1 into master May 7, 2021
@jmoguilevsky jmoguilevsky deleted the fix/fix-deployed-by-filter-capitalization branch May 7, 2021 17:52
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.

The deployedBy filter in the deployments endpoint is not filtering the deployments properly
2 participants