Skip to content

Commit

Permalink
Demographic Test
Browse files Browse the repository at this point in the history
  • Loading branch information
joey-tsai committed Nov 7, 2023
1 parent b9c3f2c commit 1d3dbc9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions api/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,8 @@ func TestSearchGift(t *testing.T) {
// Test code
w1 := httptest.NewRecorder()
w2 := httptest.NewRecorder()
w3 := httptest.NewRecorder()
w4 := httptest.NewRecorder()

// Create Gifts
testGift1 := model.Gift{
Expand Down Expand Up @@ -1177,4 +1179,33 @@ func TestSearchGift(t *testing.T) {
}

assert.GreaterOrEqual(t, len(searchOneGift), 1)

// Search Gift By Demographic
req3, err := http.NewRequest("GET", "/search?demographic=demogrpahic1", nil)
if err != nil {
t.Fatalf("Error creating request: %v", err)
}
router.ServeHTTP(w3, req3)
assert.Equal(t, 200, w3.Code)

var retrievedDemographicGifts []model.Gift
if err := json.Unmarshal(w3.Body.Bytes(), &retrievedDemographicGifts); err != nil {
t.Fatalf("Error unmarshaling JSON: %v", err)
}

assert.GreaterOrEqual(t, len(retrievedDemographicGifts), 2)

req4, err := http.NewRequest("GET", "/search?demographic=demogrpahic2", nil)
if err != nil {
t.Fatalf("Error creating request: %v", err)
}
router.ServeHTTP(w4, req4)
assert.Equal(t, 200, w4.Code)

var retrievedOneDemographicGift []model.Gift
if err := json.Unmarshal(w4.Body.Bytes(), &retrievedOneDemographicGift); err != nil {
t.Fatalf("Error unmarshaling JSON: %v", err)
}

assert.GreaterOrEqual(t, len(retrievedOneDemographicGift), 1)
}

0 comments on commit 1d3dbc9

Please sign in to comment.