UVicMartletplace / martletplace

Recreating FB Marketplace for Students - UVic SENG499 Capstone Project
0 stars 0 forks source link

Implement Reindexing API #70

Closed GDeane closed 3 months ago

GDeane commented 4 months ago

Feature Description

Implement an API to reindex the search engine whenever there is an update in the backend database.

relates: #50 - These two should be tested together blocked by: elasticsearch setup

Problem You're Trying to Solve

Ensure the search index is updated with the latest listings information.

Related External Resources

5.1.4.2

Acceptance Criteria

Unit Tests

  1. Reindex Search Results When Listing Created:

    • Test that the reindexListingCreated function processes a valid request payload correctly (creates the listing in the index).
    • Test that the reindexListingCreated function returns an appropriate success response.
    • Test that the reindexListingCreated function handles missing parameters in the request payload and returns an error response.
    • Test that the reindexListingCreated function correctly formats the listing data for reindexing.
  2. Reindex Search Results When Listing Edited:

    • Test that the reindexListingEdited function processes a valid request payload correctly (edits the listing in the index).
    • Test that the reindexListingEdited function returns an appropriate success response.
    • Test that the reindexListingEdited function handles missing parameters in the request payload and returns an error response.
    • Test that the reindexListingEdited function correctly formats the edited listing data for reindexing.
  3. Reindex Search Results When Listing Deleted:

    • Test that the reindexListingDeleted function processes a valid request payload correctly (deletes the listing from the index).
    • Test that the reindexListingDeleted function returns an appropriate success response.
    • Test that the reindexListingDeleted function handles missing parameters in the request payload and returns an error response.
    • Test that the reindexListingDeleted function correctly extracts the listing ID for reindexing.

Integration Tests

  1. Backend to Search Engine Reindexing:
    • Test that the backend correctly triggers the reindexing operation in the search engine when a listing is created.
    • Test that the backend correctly triggers the reindexing operation in the search engine when a listing is edited.
    • Test that the backend correctly triggers the reindexing operation in the search engine when a listing is deleted.
    • Test that the search engine index is updated correctly after each reindexing operation.

Acceptance Tests

  1. Listing Created Reindexing:

    • Given a new listing is created in the backend,
    • When the /api/search/reindex/listing-created endpoint is called with the correct payload,
    • Then the search engine index should be updated to include the new listing,
    • And the new listing should appear in search results.
  2. Listing Edited Reindexing:

    • Given an existing listing is edited in the backend,
    • When the /api/search/reindex/listing-edited endpoint is called with the correct payload,
    • Then the search engine index should be updated with the edited listing details,
    • And the updated listing should appear in search results.
  3. Listing Deleted Reindexing:

    • Given an existing listing is deleted in the backend,
    • When the /api/search/reindex/listing-deleted endpoint is called with the correct payload,
    • Then the search engine index should be updated to remove the deleted listing,
    • And the deleted listing should no longer appear in search results.

Example Test Scenarios

  1. Scenario: Successful Reindexing on Listing Creation

    • Given the backend creates a new listing,
    • When the reindexing API /api/search/reindex/listing-created is called with the correct payload,
    • Then the search engine index should be updated,
    • And the new listing should appear in search results.
  2. Scenario: Error Handling for Missing Parameters on Listing Creation

    • Given the backend creates a new listing,
    • When the reindexing API /api/search/reindex/listing-created is called with a missing parameter,
    • Then the API should return an error response indicating the missing parameter.
  3. Scenario: Successful Reindexing on Listing Edit

    • Given an existing listing is edited in the backend,
    • When the reindexing API /api/search/reindex/listing-edited is called with the correct payload,
    • Then the search engine index should be updated with the edited listing details,
    • And the updated listing should appear in search results.
  4. Scenario: Successful Reindexing on Listing Deletion

    • Given an existing listing is deleted in the backend,
    • When the reindexing API /api/search/reindex/listing-deleted is called with the correct payload,
    • Then the search engine index should be updated to remove the deleted listing,
    • And the deleted listing should no longer appear in search results.