created test for create product
This commit is contained in:
parent
e8775bda64
commit
a042866e86
4 changed files with 51 additions and 6 deletions
41
internal/database/claims_test.go
Normal file
41
internal/database/claims_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue