2018-10-15 20:04:17 +00:00
|
|
|
package vat_slip_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2019-02-20 19:39:37 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
2018-11-12 13:17:58 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
|
2019-02-20 19:39:37 +00:00
|
|
|
"strconv"
|
2018-10-15 20:04:17 +00:00
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_slip"
|
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Vat slip repository", func() {
|
|
|
|
var (
|
2018-11-12 13:17:58 +00:00
|
|
|
db *postgres.DB
|
|
|
|
repository vat_slip.VatSlipRepository
|
2018-10-15 20:04:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
2018-10-15 20:04:17 +00:00
|
|
|
test_config.CleanTestDB(db)
|
2018-11-12 13:17:58 +00:00
|
|
|
repository = vat_slip.VatSlipRepository{}
|
|
|
|
repository.SetDB(db)
|
2018-10-15 20:04:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Create", func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
modelWithDifferentLogIdx := test_data.VatSlipModel
|
|
|
|
modelWithDifferentLogIdx.LogIndex++
|
|
|
|
inputs := shared_behaviors.CreateBehaviorInputs{
|
|
|
|
CheckedHeaderColumnName: constants.VatSlipChecked,
|
|
|
|
LogEventTableName: "maker.vat_slip",
|
|
|
|
TestModel: test_data.VatSlipModel,
|
|
|
|
ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
|
|
|
|
Repository: &repository,
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_behaviors.SharedRepositoryCreateBehaviors(&inputs)
|
2018-10-15 20:04:17 +00:00
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
It("adds a vat slip event", func() {
|
|
|
|
headerRepository := repositories.NewHeaderRepository(db)
|
|
|
|
headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
2018-10-15 20:04:17 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
err = repository.Create(headerID, []interface{}{test_data.VatSlipModel})
|
2018-10-15 20:04:17 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
var dbVatSlip vat_slip.VatSlipModel
|
2018-10-23 21:33:04 +00:00
|
|
|
err = db.Get(&dbVatSlip, `SELECT ilk, guy, rad, tx_idx, log_idx, raw_log FROM maker.vat_slip WHERE header_id = $1`, headerID)
|
2018-10-15 20:04:17 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-02-20 19:39:37 +00:00
|
|
|
ilkID, err := shared.GetOrCreateIlk(test_data.VatSlipModel.Ilk, db)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(dbVatSlip.Ilk).To(Equal(strconv.Itoa(ilkID)))
|
2018-10-15 20:04:17 +00:00
|
|
|
Expect(dbVatSlip.Guy).To(Equal(test_data.VatSlipModel.Guy))
|
|
|
|
Expect(dbVatSlip.Rad).To(Equal(test_data.VatSlipModel.Rad))
|
|
|
|
Expect(dbVatSlip.TransactionIndex).To(Equal(test_data.VatSlipModel.TransactionIndex))
|
2018-10-23 21:33:04 +00:00
|
|
|
Expect(dbVatSlip.LogIndex).To(Equal(test_data.VatSlipModel.LogIndex))
|
2018-10-15 20:04:17 +00:00
|
|
|
Expect(dbVatSlip.Raw).To(MatchJSON(test_data.VatSlipModel.Raw))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("MarkHeaderChecked", func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
|
|
|
|
CheckedHeaderColumnName: constants.VatSlipChecked,
|
|
|
|
Repository: &repository,
|
|
|
|
}
|
2018-10-15 20:04:17 +00:00
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs)
|
2018-10-15 20:04:17 +00:00
|
|
|
})
|
|
|
|
})
|