Added unit tests for quantity itself

This commit is contained in:
konrad 2018-01-16 16:07:21 +01:00 committed by kolaente
parent 3822e4a09e
commit b613208950
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 29 additions and 0 deletions

29
models/quantity_test.go Normal file
View File

@ -0,0 +1,29 @@
package models
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetQuantity(t *testing.T) {
// Create test database
assert.NoError(t, PrepareTestDatabase())
// Set Quantity for a nonexistent item (should create)
err := SetQuantity(9999, 12)
assert.NoError(t, err)
// Check
qty, err := GetQuantity(9999)
assert.NoError(t, err)
assert.Equal(t, int64(12), qty)
// Update and check again
err = SetQuantity(9999, 120)
assert.NoError(t, err)
// Check
qty, err = GetQuantity(9999)
assert.NoError(t, err)
assert.Equal(t, int64(120), qty)
}