作者 王健

更新【company 测试用例】

package company
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -11,11 +15,32 @@ import (
var _ = Describe("公司状态转换 禁用、启用", func() {
var companyId int64
var newCompany *domain.Company
BeforeEach(func() {
newCompany = &domain.Company{
CompanyId: GinkgoRandomSeed(),
CompanyInfo: &domain.CompanyInfo{
Name: "公司名称", // 公司名称
Abbreviation: "公司简称", // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: 1, // 状态 1正常 2禁用
Remarks: "备注", // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
UserName: "用户名称", // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
"INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id",
newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt)
Expect(err).NotTo(HaveOccurred())
})
Describe("公司状态转换 禁用、启用", func() {
... ... @@ -23,10 +48,10 @@ var _ = Describe("公司状态转换 禁用、启用", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"status": "int64",
"companyId": newCompany.CompanyId,
"status": 1,
}
httpExpect.POST("/companys/convertCompanyStatus").
httpExpect.POST("/companies/convertCompanyStatus").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -39,7 +64,7 @@ var _ = Describe("公司状态转换 禁用、启用", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -17,12 +17,12 @@ var _ = Describe("创建", func() {
body := map[string]interface{}{
"name": "string",
"abbreviation": "string",
"status": "int64",
"status": 1,
"remarks": "string",
"userAccount": "string",
"userName": "string",
}
httpExpect.POST("/companys/").
httpExpect.POST("/companies/").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -36,7 +36,7 @@ var _ = Describe("创建", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -11,18 +15,39 @@ import (
var _ = Describe("返回", func() {
var companyId int64
var newCompany *domain.Company
BeforeEach(func() {
newCompany = &domain.Company{
CompanyId: GinkgoRandomSeed(),
CompanyInfo: &domain.CompanyInfo{
Name: "公司名称", // 公司名称
Abbreviation: "公司简称", // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: 1, // 状态 1正常 2禁用
Remarks: "备注", // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
UserName: "用户名称", // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
"INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id",
newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据companyId参数返回公司信息", func() {
Context("传入有效的companyId", func() {
It("返回公司信息数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/companys/{companyId}").
httpExpect.GET("/companies/" + fmt.Sprint(GinkgoRandomSeed())).
Expect().
Status(http.StatusOK).
JSON().
... ... @@ -34,7 +59,7 @@ var _ = Describe("返回", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -12,19 +16,39 @@ import (
var _ = Describe("返回列表", func() {
var companyId int64
BeforeEach(func() {
newCompany := &domain.Company{
CompanyId:GinkgoRandomSeed(),
CompanyInfo: &domain.CompanyInfo{
Name: "公司名称", // 公司名称
Abbreviation: "公司简称", // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: 1, // 状态 1正常 2禁用
Remarks: "备注", // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
UserName: "用户名称", // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
"INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id",
newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回公司信息列表", func() {
Context("传入有效的参数", func() {
It("返回公司信息数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/companys/").
WithQuery("offset", "int").
WithQuery("limit", "int").
httpExpect.GET("/companies/").
WithQuery("offset", 1).
WithQuery("limit", 1).
Expect().
Status(http.StatusOK).
JSON().
... ... @@ -33,12 +57,12 @@ var _ = Describe("返回列表", func() {
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("companys").Value("companys").Array()
ContainsKey("companies").Value("companies").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -11,18 +15,39 @@ import (
var _ = Describe("移除", func() {
var companyId int64
var newCompany *domain.Company
BeforeEach(func() {
newCompany = &domain.Company{
CompanyId: GinkgoRandomSeed(),
CompanyInfo: &domain.CompanyInfo{
Name: "公司名称", // 公司名称
Abbreviation: "公司简称", // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: 1, // 状态 1正常 2禁用
Remarks: "备注", // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
UserName: "用户名称", // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
"INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id",
newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的companyId", func() {
It("返回被移除公司信息的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/companys/{companyId}").
httpExpect.DELETE("/companies/"+fmt.Sprint(GinkgoRandomSeed())).
Expect().
Status(http.StatusOK).
JSON().
... ... @@ -34,7 +59,7 @@ var _ = Describe("移除", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -11,23 +15,45 @@ import (
var _ = Describe("设置公司管理员", func() {
var companyId int64
var newCompany *domain.Company
BeforeEach(func() {
newCompany = &domain.Company{
CompanyId:GinkgoRandomSeed(),
CompanyInfo: &domain.CompanyInfo{
Name: "公司名称", // 公司名称
Abbreviation: "公司简称", // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: 1, // 状态 1正常 2禁用
Remarks: "备注", // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
UserName: "用户名称", // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
"INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id",
newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt)
Expect(err).NotTo(HaveOccurred())
})
Describe("设置公司管理员", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"userAccount": "string",
"userName": "string",
"companyId": newCompany.CompanyId,
"userAccount": "userAccount",
"userName": "userName",
}
httpExpect.POST("/companys/setCompanyAdmin").
httpExpect.POST("/companies/setCompanyAdmin").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -40,7 +66,7 @@ var _ = Describe("设置公司管理员", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -11,11 +15,32 @@ import (
var _ = Describe("更新", func() {
var companyId int64
var newCompany *domain.Company
BeforeEach(func() {
newCompany = &domain.Company{
CompanyId: GinkgoRandomSeed(),
CompanyInfo: &domain.CompanyInfo{
Name: "公司名称", // 公司名称
Abbreviation: "公司简称", // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: 1, // 状态 1正常 2禁用
Remarks: "备注", // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
UserName: "用户名称", // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
"INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id",
newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt)
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
... ... @@ -25,12 +50,12 @@ var _ = Describe("更新", func() {
body := map[string]interface{}{
"name": "string",
"abbreviation": "string",
"status": "int64",
"status": 1,
"remarks": "string",
"userAccount": "string",
"userName": "string",
}
httpExpect.PUT("/companys/{companyId}").
httpExpect.PUT("/companies/" + fmt.Sprint(GinkgoRandomSeed())).
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -44,7 +69,7 @@ var _ = Describe("更新", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
_, err := pG.DB.Exec("DELETE FROM companies WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...