2018-10-04 21:49:09 +00:00
|
|
|
package vat_tune_test
|
|
|
|
|
|
|
|
import (
|
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"
|
2018-10-04 21:49:09 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
2018-10-11 20:25:14 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
2018-10-04 21:49:09 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
|
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Vat tune repository", func() {
|
2018-10-11 18:21:49 +00:00
|
|
|
var (
|
2018-11-12 13:17:58 +00:00
|
|
|
db *postgres.DB
|
|
|
|
repository vat_tune.VatTuneRepository
|
2018-10-11 18:21:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
2018-10-11 18:21:49 +00:00
|
|
|
test_config.CleanTestDB(db)
|
2018-11-12 13:17:58 +00:00
|
|
|
repository = vat_tune.VatTuneRepository{}
|
|
|
|
repository.SetDB(db)
|
2018-10-11 18:21:49 +00:00
|
|
|
})
|
|
|
|
|
2018-10-04 21:49:09 +00:00
|
|
|
Describe("Create", func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
modelWithDifferentLogIdx := test_data.VatTuneModel
|
|
|
|
modelWithDifferentLogIdx.LogIndex++
|
|
|
|
inputs := shared_behaviors.CreateBehaviorInputs{
|
|
|
|
CheckedHeaderColumnName: constants.VatTuneChecked,
|
|
|
|
LogEventTableName: "maker.vat_heal",
|
|
|
|
TestModel: test_data.VatTuneModel,
|
|
|
|
ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
|
|
|
|
Repository: &repository,
|
|
|
|
}
|
|
|
|
shared_behaviors.SharedRepositoryCreateBehaviors(&inputs)
|
2018-10-04 21:49:09 +00:00
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
It("adds a vat tune event", func() {
|
|
|
|
headerRepository := repositories.NewHeaderRepository(db)
|
|
|
|
headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
2018-10-04 21:49:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
err = repository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
2018-10-04 21:49:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-11 18:21:49 +00:00
|
|
|
|
2018-10-04 21:49:09 +00:00
|
|
|
var dbVatTune vat_tune.VatTuneModel
|
2018-10-23 21:33:04 +00:00
|
|
|
err = db.Get(&dbVatTune, `SELECT ilk, urn, v, w, dink, dart, tx_idx, log_idx, raw_log FROM maker.vat_tune WHERE header_id = $1`, headerID)
|
2018-10-04 21:49:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(dbVatTune.Ilk).To(Equal(test_data.VatTuneModel.Ilk))
|
|
|
|
Expect(dbVatTune.Urn).To(Equal(test_data.VatTuneModel.Urn))
|
|
|
|
Expect(dbVatTune.V).To(Equal(test_data.VatTuneModel.V))
|
|
|
|
Expect(dbVatTune.W).To(Equal(test_data.VatTuneModel.W))
|
|
|
|
Expect(dbVatTune.Dink).To(Equal(test_data.VatTuneModel.Dink))
|
|
|
|
Expect(dbVatTune.Dart).To(Equal(test_data.VatTuneModel.Dart))
|
|
|
|
Expect(dbVatTune.TransactionIndex).To(Equal(test_data.VatTuneModel.TransactionIndex))
|
2018-10-23 21:33:04 +00:00
|
|
|
Expect(dbVatTune.LogIndex).To(Equal(test_data.VatTuneModel.LogIndex))
|
2018-10-04 21:49:09 +00:00
|
|
|
Expect(dbVatTune.Raw).To(MatchJSON(test_data.VatTuneModel.Raw))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("MarkHeaderChecked", func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
|
|
|
|
CheckedHeaderColumnName: constants.VatTuneChecked,
|
|
|
|
Repository: &repository,
|
|
|
|
}
|
2018-10-04 21:49:09 +00:00
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs)
|
2018-10-04 21:49:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("MissingHeaders", func() {
|
2018-11-12 13:17:58 +00:00
|
|
|
inputs := shared_behaviors.MissingHeadersBehaviorInputs{
|
|
|
|
Repository: &repository,
|
|
|
|
RepositoryTwo: &vat_tune.VatTuneRepository{},
|
|
|
|
}
|
2018-10-04 21:49:09 +00:00
|
|
|
|
2018-11-12 13:17:58 +00:00
|
|
|
shared_behaviors.SharedRepositoryMissingHeadersBehaviors(&inputs)
|
2018-10-04 21:49:09 +00:00
|
|
|
})
|
|
|
|
})
|