42 lines
890 B
Go
42 lines
890 B
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
"vegan-barcode/internal/models"
|
|
)
|
|
|
|
func TestCreateClaimByProductId(t *testing.T) {
|
|
database := InitializeDatabase()
|
|
|
|
product, _ := database.CreateProduct("upc", "1234567890")
|
|
|
|
form := models.UserClaimForm{
|
|
Evidence_type: models.IngredientsList,
|
|
Evidence: models.IngredientsListEvidence{
|
|
Ingredients: "flour,egg,milk,water,salt,butter",
|
|
},
|
|
Claims: []models.ClaimType{
|
|
models.ContainsEggs,
|
|
models.ContainsMilk,
|
|
},
|
|
Counterclaims: []models.ClaimType{
|
|
models.ContainsMeat,
|
|
models.ContainsFish,
|
|
models.ContainsHoney,
|
|
},
|
|
Created_by: "1",
|
|
}
|
|
|
|
claim, err := database.CreateUserClaim(product.Id, form)
|
|
|
|
if err != nil {
|
|
t.Errorf("Got error while creating user claim %v", err)
|
|
}
|
|
|
|
foundClaim, _ := database.FindUserClaimById(claim.Id)
|
|
|
|
if foundClaim == nil {
|
|
t.Errorf("Could not find created claim %d", claim.Id)
|
|
}
|
|
}
|