Skip to content

Conversation

@ABradham
Copy link
Contributor

This PR Adds a dependency injected service to the src/app/homepage/homepage.component.ts file that abstracts away Firestore calls to make the component more compatible with Unit Testing.

@ABradham ABradham self-assigned this Aug 14, 2023

abstract getRestaurantCollectionData(): Observable<Restaurant[]>;

abstract getRestaurntsGivenConstraints(constraints: QueryConstraint[]): Observable<Restaurant[]>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: line length exceeds 80 - and a few more lines below

}

@Injectable()
export class MockHomepageFirestore extends HomepageFirestore {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't colocate "real" classes with fake ones. This would be better suited to live inside the test class (spec.ts).

One additional benefit there is that the test data is homed closer (as it should always be IMO) to the tests being run to make understanding the test easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha; Moved to homepage.component.spec.ts!



@Injectable()
export class DefaultHomepageFirestore extends HomepageFirestore {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: comment liberally why this is a service, why it exists, what its function is (wrt testing and injection)

*/

@Injectable()
export abstract class HomepageFirestore {
Copy link
Collaborator

@christhompsongoogle christhompsongoogle Aug 16, 2023

Choose a reason for hiding this comment

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

Is an interface possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like an interface wouldn't be @Injectable, but I've managed to move the constructor out of the abstract class in an upcoming commit!

@Injectable()
export abstract class HomepageFirestore {
store: Firestore;
constructor(store: Firestore) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if we need to use an abstract class, let's move the constructor out

return of(mockRestaurants);
}

override getRestaurntsGivenConstraints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo restaurnts

@ABradham ABradham merged commit a9f249e into master Aug 16, 2023
exaby73 pushed a commit to invertase/quickstart-js that referenced this pull request Sep 6, 2023
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.

2 participants