2019-06-06 17:07:14 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package console_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-06-26 11:38:51 +01:00
|
|
|
"storj.io/storj/internal/testrand"
|
2019-06-06 17:07:14 +01:00
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProjectInvoiceStamps(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
consoleDB := db.Console()
|
|
|
|
|
|
|
|
startDate := time.Now().UTC()
|
|
|
|
endDate := startDate.Add(time.Hour * 24)
|
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
invoiceID := testrand.Bytes(8)
|
2019-06-06 17:07:14 +01:00
|
|
|
|
|
|
|
//create project
|
|
|
|
proj, err := consoleDB.Projects().Insert(ctx, &console.Project{
|
|
|
|
Name: "test",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("create project invoice stamp", func(t *testing.T) {
|
|
|
|
stamp, err := consoleDB.ProjectInvoiceStamps().Create(ctx, console.ProjectInvoiceStamp{
|
|
|
|
ProjectID: proj.ID,
|
2019-06-26 11:38:51 +01:00
|
|
|
InvoiceID: invoiceID,
|
2019-06-06 17:07:14 +01:00
|
|
|
StartDate: startDate,
|
|
|
|
EndDate: endDate,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, proj.ID, stamp.ProjectID)
|
2019-06-26 11:38:51 +01:00
|
|
|
assert.Equal(t, invoiceID, stamp.InvoiceID)
|
2019-06-06 17:07:14 +01:00
|
|
|
assert.Equal(t, startDate.Unix(), stamp.StartDate.Unix())
|
|
|
|
assert.Equal(t, endDate.Unix(), stamp.EndDate.Unix())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get by project id and start date", func(t *testing.T) {
|
|
|
|
stamp, err := consoleDB.ProjectInvoiceStamps().GetByProjectIDStartDate(ctx, proj.ID, startDate)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, proj.ID, stamp.ProjectID)
|
2019-06-26 11:38:51 +01:00
|
|
|
assert.Equal(t, invoiceID, stamp.InvoiceID)
|
2019-06-06 17:07:14 +01:00
|
|
|
assert.Equal(t, startDate.Unix(), stamp.StartDate.Unix())
|
|
|
|
assert.Equal(t, endDate.Unix(), stamp.EndDate.Unix())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|