46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestPurchaseOrder(t *testing.T) {
|
||
|
store := NewStore(testDB)
|
||
|
supplier, _ := createRandomSupplier(t)
|
||
|
product1, _ := createRandomProduct(t)
|
||
|
product2, _ := createRandomProduct(t)
|
||
|
|
||
|
errs := make(chan error)
|
||
|
results := make(chan PurchaseOrderTxResult)
|
||
|
|
||
|
// for i := 0; i < testIteration; i++ {
|
||
|
go func() {
|
||
|
result, err := store.PurchaseOrderTx(context.Background(), PurchasoOrderTxParams{
|
||
|
MerchantID: supplier.MerchantID,
|
||
|
SupplierID: supplier.ID,
|
||
|
Code: sql.NullString{Valid: true, String: ""},
|
||
|
IsPaid: true,
|
||
|
Total: product1.PurchasePrice + product2.PurchasePrice,
|
||
|
PaidNominal: product1.PurchasePrice + product2.PurchasePrice,
|
||
|
Note: sql.NullString{Valid: true, String: ""},
|
||
|
// Products: products,
|
||
|
|
||
|
})
|
||
|
errs <- err
|
||
|
results <- result
|
||
|
}()
|
||
|
// }
|
||
|
|
||
|
// for i := 0; i < testIteration; i++ {
|
||
|
err := <-errs
|
||
|
require.NoError(t, err)
|
||
|
|
||
|
result := <-results
|
||
|
require.NotEmpty(t, result)
|
||
|
|
||
|
}
|