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

Add initial filtering capability and tests to listings service #18

Merged
merged 16 commits into from
Jun 24, 2021

Conversation

avaleske
Copy link

Issue

CityOfDetroit/affordable-housing-app#63

Addresses # (issue)

  • This change addresses the issue in full
  • This change addresses only certain aspects of the issue
  • This change is a dependency for another issue
  • This change has a dependency from another issue

Description

Adds an initial filtering capability to the listings service, and some basic tests

Details

  • Adds the ability to filter by neighborhood, using an exact string match. Other filter types will need to work differently
  • Adds test scaffolding to the Listings controller
  • Adds basic tests to the Listings service

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Prototype/POC (not to merge)
  • This change is a refactor/address technical debt
  • This change requires a documentation update
  • This change requires a SQL Script

How Can This Be Tested/Reviewed?

Please describe the tests that you ran to verify your changes. Provide instructions so we can review. Please also list any relevant details for your test configuration

  • Run yarn test -t "listings" to run the new tests
  • Navigate to localhost:3100/listings?neighborhood=Fox%20Creek and observe that the listings are filtered. Try replacing with other neighborhood names (run select neighborhood, count(*) from property group by neighborhood; in the db to see them all)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have reviewed the changes in a desktop view
  • I have reviewed the changes in a mobile view
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have assigned reviewers
  • I have updated the changelog to include a description of my changes

Copy link

@anders-schneider anders-schneider left a comment

Choose a reason for hiding this comment

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

LGTM

And thanks for adding the test scaffolding!

backend/core/src/listings/listings.service.ts Outdated Show resolved Hide resolved
@anders-schneider
Copy link

One other question here: should the tests live in /backend/core/src or /backend/core/test? So far it looks like there are only e2e tests in /backend/core/test, but my instinct would be to add these unit tests to that test directory. There may be a good reason to include them in /backend/core/src, though?

@avaleske
Copy link
Author

@anders-schneider the other unit tests are in the same directory as the code under test, for example: https://github.com/CityOfDetroit/bloom/blob/main/backend/core/src/user/user.controller.spec.ts

@anders-schneider
Copy link

Ah sorry I missed that, sounds good on including unit tests in the same directory like you have it!


@Injectable()
export class ListingsService {
constructor(@InjectRepository(Listing) private readonly repository: Repository<Listing>) {}

private getQueryBuilder() {
return Listing.createQueryBuilder("listings")
return this.repository

Choose a reason for hiding this comment

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

Why the switch here and elsewhere to use this.repository instead of Listing?

Copy link
Author

Choose a reason for hiding this comment

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

Listing is using the entity object directly, but this.repository is the injected entity. That lets me swap it with a mock in the tests.

@avaleske avaleske merged commit 1daff0a into main Jun 24, 2021
@avaleske avaleske deleted the feature/avaleske-initial-filters branch June 24, 2021 20:17
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.

3 participants