ipld-eth-server/pkg/transformers/vat_slip/repository_test.go

72 lines
2.6 KiB
Go
Raw Normal View History

2018-10-15 20:04:17 +00:00
package vat_slip_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
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 (
db *postgres.DB
repository vat_slip.VatSlipRepository
2018-10-15 20:04:17 +00:00
)
BeforeEach(func() {
db = test_config.NewTestDB(test_config.NewTestNode())
2018-10-15 20:04:17 +00:00
test_config.CleanTestDB(db)
repository = vat_slip.VatSlipRepository{}
repository.SetDB(db)
2018-10-15 20:04:17 +00:00
})
Describe("Create", func() {
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
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())
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
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())
Expect(dbVatSlip.Ilk).To(Equal(test_data.VatSlipModel.Ilk))
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))
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() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: constants.VatSlipChecked,
Repository: &repository,
}
2018-10-15 20:04:17 +00:00
shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs)
2018-10-15 20:04:17 +00:00
})
})