2018-08-07 15:51:34 +00:00
|
|
|
// Copyright 2018 Vulcanize
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2018-11-12 16:50:51 +00:00
|
|
|
Describe("missing headers", func() {
|
|
|
|
inputs := shared_behaviors.MissingHeadersBehaviorInputs{
|
|
|
|
Repository: &flipKickRepository,
|
|
|
|
RepositoryTwo: &flip_kick.FlipKickRepository{},
|
|
|
|
}
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-11-12 16:50:51 +00:00
|
|
|
shared_behaviors.SharedRepositoryMissingHeadersBehaviors(&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))
|
|
|
|
}
|