update_file_test.go 1.4 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{}{}
				httpExpect.PUT("/files/{fileId}").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("fileId").ValueEqual("fileId", fileId)
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM files WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})