generate_main_table_test.go 1.3 KB
package file

import (
	"github.com/go-pg/pg/v10"
	"net/http"

	"github.com/gavv/httpexpect"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)

var _ = Describe("生成主表", func() {
	var fileId int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&fileId),
			"INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id",
			"testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion")
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("生成主表", func() {
		Context("", func() {
			It("", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"fileId": "int",
				}
				httpExpect.POST("/files/files/generate-main-table").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object()
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM files WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})