Skip to content

Commit

Permalink
Add tests for previous price.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhowse committed Aug 21, 2024
1 parent c9d9a1a commit ffcda79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/woolworths/woolworths.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (w *Woolworths) GetSharedProductsUpdatedAfter(t time.Time, count int) ([]sh
products.description,
departments.description,
priceCents,
previousPriceCents,
weightGrams,
products.updated
FROM
Expand All @@ -53,7 +54,15 @@ func (w *Woolworths) GetSharedProductsUpdatedAfter(t time.Time, count int) ([]sh
}
for rows.Next() {
var product shared.ProductInfo
err = rows.Scan(&product.ID, &product.Name, &product.Description, &deptDescription, &product.PriceCents, &product.WeightGrams, &product.Timestamp)
err = rows.Scan(
&product.ID,
&product.Name,
&product.Description,
&deptDescription,
&product.PriceCents,
&product.PreviousPriceCents,
&product.WeightGrams,
&product.Timestamp)
if err != nil {
return productIDs, fmt.Errorf("failed to scan productID: %w", err)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/woolworths/woolworths_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func TestGetSharedProductsUpdatedAfter(t *testing.T) {
infoList = append(infoList, woolworthsProductInfo{ID: "123456", Info: productListPageProduct{DisplayName: "2", Price: decimal.NewFromFloat(2.4)}, Updated: time.Now().Add(-4 * time.Minute)})
infoList = append(infoList, woolworthsProductInfo{ID: "123457", Info: productListPageProduct{DisplayName: "3", Price: decimal.NewFromFloat(3.3)}, Updated: time.Now().Add(-3 * time.Minute)})
infoList = append(infoList, woolworthsProductInfo{ID: "123458", Info: productListPageProduct{DisplayName: "4", Price: decimal.NewFromFloat(4.2)}, Updated: time.Now().Add(-1 * time.Minute)})
// Put this one in twice to test the PreviousPriceCents is updated.
infoList = append(infoList, woolworthsProductInfo{ID: "123459", Info: productListPageProduct{DisplayName: "5", Price: decimal.NewFromFloat(5.0)}, Updated: time.Now()})
infoList = append(infoList, woolworthsProductInfo{ID: "123459", Info: productListPageProduct{DisplayName: "5", Price: decimal.NewFromFloat(5.1)}, Updated: time.Now()})
// This last one is to test that we don't get products that have a blank name.
infoList = append(infoList, woolworthsProductInfo{ID: "123460", Info: productListPageProduct{DisplayName: "", Price: decimal.NewFromFloat(6.0)}, Updated: time.Now()})
Expand All @@ -110,6 +112,9 @@ func TestGetSharedProductsUpdatedAfter(t *testing.T) {
if want, got := WOOLWORTHS_ID_PREFIX+"123459", productIDs[1].ID; want != got {
t.Errorf("Expected %s, got %s", want, got)
}
if want, got := 500, productIDs[1].PreviousPriceCents; want != got {
t.Errorf("Expected %v, got %v", want, got)
}
if want, got := 510, productIDs[1].PriceCents; want != got {
t.Errorf("Expected %v, got %v", want, got)
}
Expand Down

0 comments on commit ffcda79

Please sign in to comment.