2019-01-24 20:41:30 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-07 20:17:29 +00:00
|
|
|
package flip_kick_test
|
2018-08-07 15:51:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
. "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-08-07 20:17:29 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
2018-11-12 16:50:51 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
2018-08-07 20:17:29 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
2018-11-12 16:50:51 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
|
2018-08-07 15:51:34 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("FlipKick Repository", func() {
|
|
|
|
var db *postgres.DB
|
2018-08-07 20:17:29 +00:00
|
|
|
var flipKickRepository flip_kick.FlipKickRepository
|
2018-08-07 15:51:34 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-10-11 18:21:49 +00:00
|
|
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
2018-08-07 20:17:29 +00:00
|
|
|
test_config.CleanTestDB(db)
|
2018-11-02 14:12:51 +00:00
|
|
|
flipKickRepository = flip_kick.FlipKickRepository{}
|
|
|
|
flipKickRepository.SetDB(db)
|
2018-08-07 15:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Create", func() {
|
2018-11-12 16:50:51 +00:00
|
|
|
modelWithDifferentLogIdx := test_data.FlipKickModel
|
|
|
|
modelWithDifferentLogIdx.LogIndex++
|
|
|
|
inputs := shared_behaviors.CreateBehaviorInputs{
|
|
|
|
CheckedHeaderColumnName: constants.FlipKickChecked,
|
|
|
|
LogEventTableName: "maker.flip_kick",
|
|
|
|
TestModel: test_data.FlipKickModel,
|
|
|
|
ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
|
|
|
|
Repository: &flipKickRepository,
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_behaviors.SharedRepositoryCreateBehaviors(&inputs)
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-09-20 20:13:37 +00:00
|
|
|
It("persists flip_kick records", func() {
|
2018-11-12 16:50:51 +00:00
|
|
|
headerRepository := repositories.NewHeaderRepository(db)
|
|
|
|
headerId, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
err = flipKickRepository.Create(headerId, []interface{}{test_data.FlipKickModel})
|
2018-08-07 15:51:34 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
assertDBRecordCount(db, "maker.flip_kick", 1)
|
|
|
|
|
|
|
|
dbResult := test_data.FlipKickDBRow{}
|
2018-11-02 14:12:51 +00:00
|
|
|
err = db.QueryRowx(`SELECT * FROM maker.flip_kick`).StructScan(&dbResult)
|
2018-08-07 15:51:34 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(dbResult.HeaderId).To(Equal(headerId))
|
2018-11-12 16:50:51 +00:00
|
|
|
Expect(dbResult.BidId).To(Equal(test_data.FlipKickModel.BidId))
|
|
|
|
Expect(dbResult.Lot).To(Equal(test_data.FlipKickModel.Lot))
|
|
|
|
Expect(dbResult.Bid).To(Equal(test_data.FlipKickModel.Bid))
|
|
|
|
Expect(dbResult.Gal).To(Equal(test_data.FlipKickModel.Gal))
|
|
|
|
Expect(dbResult.End.Equal(test_data.FlipKickModel.End)).To(BeTrue())
|
|
|
|
Expect(dbResult.Urn).To(Equal(test_data.FlipKickModel.Urn))
|
|
|
|
Expect(dbResult.Tab).To(Equal(test_data.FlipKickModel.Tab))
|
|
|
|
Expect(dbResult.TransactionIndex).To(Equal(test_data.FlipKickModel.TransactionIndex))
|
|
|
|
Expect(dbResult.LogIndex).To(Equal(test_data.FlipKickModel.LogIndex))
|
|
|
|
Expect(dbResult.Raw).To(MatchJSON(test_data.FlipKickModel.Raw))
|
2018-11-02 14:12:51 +00:00
|
|
|
})
|
2018-08-07 15:51:34 +00:00
|
|
|
})
|
|
|
|
|
2018-09-20 20:13:37 +00:00
|
|
|
Describe("MarkHeaderChecked", func() {
|
2018-11-12 16:50:51 +00:00
|
|
|
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
|
|
|
|
CheckedHeaderColumnName: constants.FlipKickChecked,
|
|
|
|
Repository: &flipKickRepository,
|
|
|
|
}
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-11-12 16:50:51 +00:00
|
|
|
shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs)
|
2018-08-07 15:51:34 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
func assertDBRecordCount(db *postgres.DB, dbTable string, expectedCount int) {
|
|
|
|
var count int
|
|
|
|
query := `SELECT count(*) FROM ` + dbTable
|
|
|
|
err := db.QueryRow(query).Scan(&count)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(count).To(Equal(expectedCount))
|
|
|
|
}
|