ipld-eth-server/pkg/transformers/price_feeds/pep/repository_test.go

52 lines
1.6 KiB
Go
Raw Normal View History

2018-07-24 16:38:49 +00:00
package pep_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
2018-07-26 18:57:38 +00:00
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds"
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds/pep"
2018-07-24 16:38:49 +00:00
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("Pep repository", func() {
2018-07-26 18:57:38 +00:00
It("returns header if matching header does not exist", func() {
db := test_config.NewTestDB(core.Node{})
repository := pep.NewPepRepository(db)
pepToAdd := price_feeds.PriceUpdate{
BlockNumber: 0,
HeaderID: 0,
UsdValue: "123.456",
}
err := repository.CreatePep(pepToAdd)
Expect(err).To(HaveOccurred())
})
It("creates a pep when matching header exists", func() {
2018-07-24 16:38:49 +00:00
db := test_config.NewTestDB(core.Node{})
test_config.CleanTestDB(db)
repository := pep.NewPepRepository(db)
header := core.Header{BlockNumber: 12345}
headerRepository := repositories.NewHeaderRepository(db)
headerID, err := headerRepository.CreateOrUpdateHeader(header)
Expect(err).NotTo(HaveOccurred())
2018-07-26 18:57:38 +00:00
pepToAdd := price_feeds.PriceUpdate{
2018-07-24 16:38:49 +00:00
BlockNumber: header.BlockNumber,
HeaderID: headerID,
UsdValue: "123.456",
}
err = repository.CreatePep(pepToAdd)
Expect(err).NotTo(HaveOccurred())
2018-07-26 18:57:38 +00:00
var dbPep price_feeds.PriceUpdate
2018-07-24 16:38:49 +00:00
err = db.Get(&dbPep, `SELECT block_number, header_id, usd_value FROM maker.peps WHERE header_id = $1`, pepToAdd.HeaderID)
Expect(err).NotTo(HaveOccurred())
Expect(dbPep).To(Equal(pepToAdd))
})
})