get_file_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("根据fileId参数返回文件", func() {
		Context("传入有效的fileId", func() {
			It("返回文件数据", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/files/{fileId}").
					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())
	})
})