2019-01-24 20:41:30 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2019-01-24 20:41:30 +00:00
|
|
|
|
|
|
|
// 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-12-04 15:04:13 +00:00
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
package repository_test
|
2018-12-04 15:04:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2019-08-06 21:57:08 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/repository"
|
2018-12-13 12:58:16 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
2018-12-04 15:04:13 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
2019-08-06 21:57:08 +00:00
|
|
|
var _ = Describe("", func() {
|
|
|
|
Describe("MarkContractWatcherHeaderCheckedInTransaction", func() {
|
|
|
|
var (
|
|
|
|
checkedHeadersColumn string
|
|
|
|
db *postgres.DB
|
|
|
|
)
|
2019-02-28 14:59:04 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
|
|
|
test_config.CleanTestDB(db)
|
|
|
|
checkedHeadersColumn = "test_column_checked"
|
|
|
|
_, migrateErr := db.Exec(`ALTER TABLE public.checked_headers
|
|
|
|
ADD COLUMN ` + checkedHeadersColumn + ` integer`)
|
|
|
|
Expect(migrateErr).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
_, cleanupMigrateErr := db.Exec(`ALTER TABLE public.checked_headers DROP COLUMN ` + checkedHeadersColumn)
|
|
|
|
Expect(cleanupMigrateErr).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
2019-08-06 21:57:08 +00:00
|
|
|
It("marks passed header as checked within a passed transaction", func() {
|
2019-02-28 14:59:04 +00:00
|
|
|
headerRepository := repositories.NewHeaderRepository(db)
|
|
|
|
headerID, headerErr := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
|
|
|
Expect(headerErr).NotTo(HaveOccurred())
|
2019-03-06 16:15:32 +00:00
|
|
|
tx, txErr := db.Beginx()
|
2019-02-28 14:59:04 +00:00
|
|
|
Expect(txErr).NotTo(HaveOccurred())
|
|
|
|
|
2019-08-06 21:57:08 +00:00
|
|
|
err := repository.MarkContractWatcherHeaderCheckedInTransaction(headerID, tx, checkedHeadersColumn)
|
2019-02-28 14:59:04 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
commitErr := tx.Commit()
|
|
|
|
Expect(commitErr).NotTo(HaveOccurred())
|
|
|
|
var checkedCount int
|
2019-08-06 21:57:08 +00:00
|
|
|
fetchErr := db.Get(&checkedCount, `SELECT COUNT(*) FROM public.checked_headers WHERE header_id = $1`, headerID)
|
2019-02-28 14:59:04 +00:00
|
|
|
Expect(fetchErr).NotTo(HaveOccurred())
|
|
|
|
Expect(checkedCount).To(Equal(1))
|
|
|
|
})
|
|
|
|
})
|
2018-12-04 15:04:13 +00:00
|
|
|
})
|