作者 tangxuhui

添加 test

... ... @@ -27,6 +27,9 @@ func init() {
if !constant.DISABLE_CREATE_TABLE {
tables := []interface{}{
&models.Dictionary{},
&models.NoticePersonal{},
&models.NoticeSetting{},
&models.SystemSetting{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
... ... @@ -23,8 +23,8 @@ var _ = Describe("返回数据字典设置列表", func() {
It("返回字典数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/dictionarys/").
WithQuery("offset", "int").
WithQuery("limit", "int").
WithQuery("offset", "string").
WithQuery("limit", "string").
Expect().
Status(http.StatusOK).
JSON().
... ...
... ... @@ -23,10 +23,10 @@ var _ = Describe("获取消息列表", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userId": "int64",
"offset": "int64",
"limit": "int64",
"isRead": "int64",
"userId": "int64",
"pageIndex": "int",
"pageSize": "int",
"isRead": "int64",
}
httpExpect.POST("/notice-personal/").
WithJSON(body).
... ...
package system_setting
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg"
)
var _ = Describe("返回用户的系统设置", func() {
var systemSettingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&systemSettingId),
"INSERT INTO system_settings (company_id, control_level, description, setting_code, setting_name, system_setting_id, value, value_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING system_setting_id",
"testCompanyId", "testControlLevel", "testDescription", "testSettingCode", "testSettingName", "testSystemSettingId", "testValue", "testValueType")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据systemSettingId参数返回系统参数设置", func() {
Context("传入有效的systemSettingId", func() {
It("返回系统参数设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"settingCode": "string",
"companyId": "int64",
}
httpExpect.POST("/system-settings/get").
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 system_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package system_setting
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg"
)
var _ = Describe("返回用户的系统设置列表", func() {
var systemSettingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&systemSettingId),
"INSERT INTO system_settings (company_id, control_level, description, setting_code, setting_name, system_setting_id, value, value_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING system_setting_id",
"testCompanyId", "testControlLevel", "testDescription", "testSettingCode", "testSettingName", "testSystemSettingId", "testValue", "testValueType")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回系统参数设置列表", func() {
Context("传入有效的参数", func() {
It("返回系统参数设置数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"settingCode": "string",
}
httpExpect.POST("/system-settings/search").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("systemSettings").Value("systemSettings").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM system_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package system_setting
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego"
)
func TestSystemSetting(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port SystemSetting Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package system_setting
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg"
)
var _ = Describe("更新用户的系统设置", func() {
var systemSettingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&systemSettingId),
"INSERT INTO system_settings (company_id, control_level, description, setting_code, setting_name, system_setting_id, value, value_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING system_setting_id",
"testCompanyId", "testControlLevel", "testDescription", "testSettingCode", "testSettingName", "testSystemSettingId", "testValue", "testValueType")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新用户的系统设置", func() {
Context("提交正确的系统参数设置数据", func() {
It("返回更新后的系统参数设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"settingCode": "string",
"companyId": "int64",
}
httpExpect.PUT("/system-settings/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("systemSettingId").ValueEqual("systemSettingId", systemSettingId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM system_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...