正在显示
7 个修改的文件
包含
186 行增加
和
36 行删除
1 | package company | 1 | package company |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
4 | "net/http" | 7 | "net/http" |
8 | + "time" | ||
5 | 9 | ||
6 | "github.com/gavv/httpexpect" | 10 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 11 | . "github.com/onsi/ginkgo" |
@@ -11,11 +15,32 @@ import ( | @@ -11,11 +15,32 @@ import ( | ||
11 | 15 | ||
12 | var _ = Describe("公司状态转换 禁用、启用", func() { | 16 | var _ = Describe("公司状态转换 禁用、启用", func() { |
13 | var companyId int64 | 17 | var companyId int64 |
18 | + var newCompany *domain.Company | ||
14 | BeforeEach(func() { | 19 | BeforeEach(func() { |
20 | + newCompany = &domain.Company{ | ||
21 | + CompanyId: GinkgoRandomSeed(), | ||
22 | + CompanyInfo: &domain.CompanyInfo{ | ||
23 | + Name: "公司名称", // 公司名称 | ||
24 | + Abbreviation: "公司简称", // 公司简称 | ||
25 | + Logo: "", // 公司logo | ||
26 | + Phone: "", // 公司联系电话 | ||
27 | + Status: 1, // 状态 1正常 2禁用 | ||
28 | + Remarks: "备注", // 备注 | ||
29 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
30 | + Admin: &domain.CompanyAdmin{ | ||
31 | + UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 | ||
32 | + UserName: "用户名称", // 用户名称 | ||
33 | + }, // 公司主管理员 | ||
34 | + }, | ||
35 | + CreateAt: time.Now(), | ||
36 | + UpdateAt: time.Now(), | ||
37 | + } | ||
38 | + | ||
15 | _, err := pG.DB.QueryOne( | 39 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(&companyId), | 40 | pg.Scan(&companyId), |
17 | - "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | - "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | 41 | + "INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id", |
42 | + newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt) | ||
43 | + | ||
19 | Expect(err).NotTo(HaveOccurred()) | 44 | Expect(err).NotTo(HaveOccurred()) |
20 | }) | 45 | }) |
21 | Describe("公司状态转换 禁用、启用", func() { | 46 | Describe("公司状态转换 禁用、启用", func() { |
@@ -23,10 +48,10 @@ var _ = Describe("公司状态转换 禁用、启用", func() { | @@ -23,10 +48,10 @@ var _ = Describe("公司状态转换 禁用、启用", func() { | ||
23 | It("", func() { | 48 | It("", func() { |
24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 49 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
25 | body := map[string]interface{}{ | 50 | body := map[string]interface{}{ |
26 | - "companyId": "int64", | ||
27 | - "status": "int64", | 51 | + "companyId": newCompany.CompanyId, |
52 | + "status": 1, | ||
28 | } | 53 | } |
29 | - httpExpect.POST("/companys/convertCompanyStatus"). | 54 | + httpExpect.POST("/companies/convertCompanyStatus"). |
30 | WithJSON(body). | 55 | WithJSON(body). |
31 | Expect(). | 56 | Expect(). |
32 | Status(http.StatusOK). | 57 | Status(http.StatusOK). |
@@ -39,7 +64,7 @@ var _ = Describe("公司状态转换 禁用、启用", func() { | @@ -39,7 +64,7 @@ var _ = Describe("公司状态转换 禁用、启用", func() { | ||
39 | }) | 64 | }) |
40 | }) | 65 | }) |
41 | AfterEach(func() { | 66 | AfterEach(func() { |
42 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 67 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
43 | Expect(err).NotTo(HaveOccurred()) | 68 | Expect(err).NotTo(HaveOccurred()) |
44 | }) | 69 | }) |
45 | }) | 70 | }) |
@@ -17,12 +17,12 @@ var _ = Describe("创建", func() { | @@ -17,12 +17,12 @@ var _ = Describe("创建", func() { | ||
17 | body := map[string]interface{}{ | 17 | body := map[string]interface{}{ |
18 | "name": "string", | 18 | "name": "string", |
19 | "abbreviation": "string", | 19 | "abbreviation": "string", |
20 | - "status": "int64", | 20 | + "status": 1, |
21 | "remarks": "string", | 21 | "remarks": "string", |
22 | "userAccount": "string", | 22 | "userAccount": "string", |
23 | "userName": "string", | 23 | "userName": "string", |
24 | } | 24 | } |
25 | - httpExpect.POST("/companys/"). | 25 | + httpExpect.POST("/companies/"). |
26 | WithJSON(body). | 26 | WithJSON(body). |
27 | Expect(). | 27 | Expect(). |
28 | Status(http.StatusOK). | 28 | Status(http.StatusOK). |
@@ -36,7 +36,7 @@ var _ = Describe("创建", func() { | @@ -36,7 +36,7 @@ var _ = Describe("创建", func() { | ||
36 | }) | 36 | }) |
37 | }) | 37 | }) |
38 | AfterEach(func() { | 38 | AfterEach(func() { |
39 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 39 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
40 | Expect(err).NotTo(HaveOccurred()) | 40 | Expect(err).NotTo(HaveOccurred()) |
41 | }) | 41 | }) |
42 | }) | 42 | }) |
1 | package company | 1 | package company |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
4 | "net/http" | 7 | "net/http" |
8 | + "time" | ||
5 | 9 | ||
6 | "github.com/gavv/httpexpect" | 10 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 11 | . "github.com/onsi/ginkgo" |
@@ -11,18 +15,39 @@ import ( | @@ -11,18 +15,39 @@ import ( | ||
11 | 15 | ||
12 | var _ = Describe("返回", func() { | 16 | var _ = Describe("返回", func() { |
13 | var companyId int64 | 17 | var companyId int64 |
18 | + var newCompany *domain.Company | ||
14 | BeforeEach(func() { | 19 | BeforeEach(func() { |
20 | + newCompany = &domain.Company{ | ||
21 | + CompanyId: GinkgoRandomSeed(), | ||
22 | + CompanyInfo: &domain.CompanyInfo{ | ||
23 | + Name: "公司名称", // 公司名称 | ||
24 | + Abbreviation: "公司简称", // 公司简称 | ||
25 | + Logo: "", // 公司logo | ||
26 | + Phone: "", // 公司联系电话 | ||
27 | + Status: 1, // 状态 1正常 2禁用 | ||
28 | + Remarks: "备注", // 备注 | ||
29 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
30 | + Admin: &domain.CompanyAdmin{ | ||
31 | + UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 | ||
32 | + UserName: "用户名称", // 用户名称 | ||
33 | + }, // 公司主管理员 | ||
34 | + }, | ||
35 | + CreateAt: time.Now(), | ||
36 | + UpdateAt: time.Now(), | ||
37 | + } | ||
38 | + | ||
15 | _, err := pG.DB.QueryOne( | 39 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(&companyId), | 40 | pg.Scan(&companyId), |
17 | - "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | - "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | 41 | + "INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id", |
42 | + newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt) | ||
43 | + | ||
19 | Expect(err).NotTo(HaveOccurred()) | 44 | Expect(err).NotTo(HaveOccurred()) |
20 | }) | 45 | }) |
21 | Describe("根据companyId参数返回公司信息", func() { | 46 | Describe("根据companyId参数返回公司信息", func() { |
22 | Context("传入有效的companyId", func() { | 47 | Context("传入有效的companyId", func() { |
23 | It("返回公司信息数据", func() { | 48 | It("返回公司信息数据", func() { |
24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 49 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
25 | - httpExpect.GET("/companys/{companyId}"). | 50 | + httpExpect.GET("/companies/" + fmt.Sprint(GinkgoRandomSeed())). |
26 | Expect(). | 51 | Expect(). |
27 | Status(http.StatusOK). | 52 | Status(http.StatusOK). |
28 | JSON(). | 53 | JSON(). |
@@ -34,7 +59,7 @@ var _ = Describe("返回", func() { | @@ -34,7 +59,7 @@ var _ = Describe("返回", func() { | ||
34 | }) | 59 | }) |
35 | }) | 60 | }) |
36 | AfterEach(func() { | 61 | AfterEach(func() { |
37 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 62 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
38 | Expect(err).NotTo(HaveOccurred()) | 63 | Expect(err).NotTo(HaveOccurred()) |
39 | }) | 64 | }) |
40 | }) | 65 | }) |
1 | package company | 1 | package company |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
4 | "net/http" | 7 | "net/http" |
8 | + "time" | ||
5 | 9 | ||
6 | "github.com/gavv/httpexpect" | 10 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 11 | . "github.com/onsi/ginkgo" |
@@ -12,19 +16,39 @@ import ( | @@ -12,19 +16,39 @@ import ( | ||
12 | var _ = Describe("返回列表", func() { | 16 | var _ = Describe("返回列表", func() { |
13 | var companyId int64 | 17 | var companyId int64 |
14 | BeforeEach(func() { | 18 | BeforeEach(func() { |
19 | + newCompany := &domain.Company{ | ||
20 | + CompanyId:GinkgoRandomSeed(), | ||
21 | + CompanyInfo: &domain.CompanyInfo{ | ||
22 | + Name: "公司名称", // 公司名称 | ||
23 | + Abbreviation: "公司简称", // 公司简称 | ||
24 | + Logo: "", // 公司logo | ||
25 | + Phone: "", // 公司联系电话 | ||
26 | + Status: 1, // 状态 1正常 2禁用 | ||
27 | + Remarks: "备注", // 备注 | ||
28 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
29 | + Admin: &domain.CompanyAdmin{ | ||
30 | + UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 | ||
31 | + UserName: "用户名称", // 用户名称 | ||
32 | + }, // 公司主管理员 | ||
33 | + }, | ||
34 | + CreateAt: time.Now(), | ||
35 | + UpdateAt: time.Now(), | ||
36 | + } | ||
37 | + | ||
15 | _, err := pG.DB.QueryOne( | 38 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(&companyId), | 39 | pg.Scan(&companyId), |
17 | - "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | - "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | 40 | + "INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id", |
41 | + newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt) | ||
42 | + | ||
19 | Expect(err).NotTo(HaveOccurred()) | 43 | Expect(err).NotTo(HaveOccurred()) |
20 | }) | 44 | }) |
21 | Describe("根据参数返回公司信息列表", func() { | 45 | Describe("根据参数返回公司信息列表", func() { |
22 | Context("传入有效的参数", func() { | 46 | Context("传入有效的参数", func() { |
23 | It("返回公司信息数据列表", func() { | 47 | It("返回公司信息数据列表", func() { |
24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 48 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
25 | - httpExpect.GET("/companys/"). | ||
26 | - WithQuery("offset", "int"). | ||
27 | - WithQuery("limit", "int"). | 49 | + httpExpect.GET("/companies/"). |
50 | + WithQuery("offset", 1). | ||
51 | + WithQuery("limit", 1). | ||
28 | Expect(). | 52 | Expect(). |
29 | Status(http.StatusOK). | 53 | Status(http.StatusOK). |
30 | JSON(). | 54 | JSON(). |
@@ -33,12 +57,12 @@ var _ = Describe("返回列表", func() { | @@ -33,12 +57,12 @@ var _ = Describe("返回列表", func() { | ||
33 | ContainsKey("msg").ValueEqual("msg", "ok"). | 57 | ContainsKey("msg").ValueEqual("msg", "ok"). |
34 | ContainsKey("data").Value("data").Object(). | 58 | ContainsKey("data").Value("data").Object(). |
35 | ContainsKey("count").ValueEqual("count", 1). | 59 | ContainsKey("count").ValueEqual("count", 1). |
36 | - ContainsKey("companys").Value("companys").Array() | 60 | + ContainsKey("companies").Value("companies").Array() |
37 | }) | 61 | }) |
38 | }) | 62 | }) |
39 | }) | 63 | }) |
40 | AfterEach(func() { | 64 | AfterEach(func() { |
41 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 65 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
42 | Expect(err).NotTo(HaveOccurred()) | 66 | Expect(err).NotTo(HaveOccurred()) |
43 | }) | 67 | }) |
44 | }) | 68 | }) |
1 | package company | 1 | package company |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
4 | "net/http" | 7 | "net/http" |
8 | + "time" | ||
5 | 9 | ||
6 | "github.com/gavv/httpexpect" | 10 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 11 | . "github.com/onsi/ginkgo" |
@@ -11,18 +15,39 @@ import ( | @@ -11,18 +15,39 @@ import ( | ||
11 | 15 | ||
12 | var _ = Describe("移除", func() { | 16 | var _ = Describe("移除", func() { |
13 | var companyId int64 | 17 | var companyId int64 |
18 | + var newCompany *domain.Company | ||
14 | BeforeEach(func() { | 19 | BeforeEach(func() { |
20 | + newCompany = &domain.Company{ | ||
21 | + CompanyId: GinkgoRandomSeed(), | ||
22 | + CompanyInfo: &domain.CompanyInfo{ | ||
23 | + Name: "公司名称", // 公司名称 | ||
24 | + Abbreviation: "公司简称", // 公司简称 | ||
25 | + Logo: "", // 公司logo | ||
26 | + Phone: "", // 公司联系电话 | ||
27 | + Status: 1, // 状态 1正常 2禁用 | ||
28 | + Remarks: "备注", // 备注 | ||
29 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
30 | + Admin: &domain.CompanyAdmin{ | ||
31 | + UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 | ||
32 | + UserName: "用户名称", // 用户名称 | ||
33 | + }, // 公司主管理员 | ||
34 | + }, | ||
35 | + CreateAt: time.Now(), | ||
36 | + UpdateAt: time.Now(), | ||
37 | + } | ||
38 | + | ||
15 | _, err := pG.DB.QueryOne( | 39 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(&companyId), | 40 | pg.Scan(&companyId), |
17 | - "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | - "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | 41 | + "INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id", |
42 | + newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt) | ||
43 | + | ||
19 | Expect(err).NotTo(HaveOccurred()) | 44 | Expect(err).NotTo(HaveOccurred()) |
20 | }) | 45 | }) |
21 | Describe("根据参数移除", func() { | 46 | Describe("根据参数移除", func() { |
22 | Context("传入有效的companyId", func() { | 47 | Context("传入有效的companyId", func() { |
23 | It("返回被移除公司信息的数据", func() { | 48 | It("返回被移除公司信息的数据", func() { |
24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 49 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
25 | - httpExpect.DELETE("/companys/{companyId}"). | 50 | + httpExpect.DELETE("/companies/"+fmt.Sprint(GinkgoRandomSeed())). |
26 | Expect(). | 51 | Expect(). |
27 | Status(http.StatusOK). | 52 | Status(http.StatusOK). |
28 | JSON(). | 53 | JSON(). |
@@ -34,7 +59,7 @@ var _ = Describe("移除", func() { | @@ -34,7 +59,7 @@ var _ = Describe("移除", func() { | ||
34 | }) | 59 | }) |
35 | }) | 60 | }) |
36 | AfterEach(func() { | 61 | AfterEach(func() { |
37 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 62 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
38 | Expect(err).NotTo(HaveOccurred()) | 63 | Expect(err).NotTo(HaveOccurred()) |
39 | }) | 64 | }) |
40 | }) | 65 | }) |
1 | package company | 1 | package company |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
4 | "net/http" | 7 | "net/http" |
8 | + "time" | ||
5 | 9 | ||
6 | "github.com/gavv/httpexpect" | 10 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 11 | . "github.com/onsi/ginkgo" |
@@ -11,23 +15,45 @@ import ( | @@ -11,23 +15,45 @@ import ( | ||
11 | 15 | ||
12 | var _ = Describe("设置公司管理员", func() { | 16 | var _ = Describe("设置公司管理员", func() { |
13 | var companyId int64 | 17 | var companyId int64 |
18 | + var newCompany *domain.Company | ||
14 | BeforeEach(func() { | 19 | BeforeEach(func() { |
20 | + newCompany = &domain.Company{ | ||
21 | + CompanyId:GinkgoRandomSeed(), | ||
22 | + CompanyInfo: &domain.CompanyInfo{ | ||
23 | + Name: "公司名称", // 公司名称 | ||
24 | + Abbreviation: "公司简称", // 公司简称 | ||
25 | + Logo: "", // 公司logo | ||
26 | + Phone: "", // 公司联系电话 | ||
27 | + Status: 1, // 状态 1正常 2禁用 | ||
28 | + Remarks: "备注", // 备注 | ||
29 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
30 | + Admin: &domain.CompanyAdmin{ | ||
31 | + UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 | ||
32 | + UserName: "用户名称", // 用户名称 | ||
33 | + }, // 公司主管理员 | ||
34 | + }, | ||
35 | + CreateAt: time.Now(), | ||
36 | + UpdateAt: time.Now(), | ||
37 | + } | ||
38 | + | ||
15 | _, err := pG.DB.QueryOne( | 39 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(&companyId), | 40 | pg.Scan(&companyId), |
17 | - "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | - "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | 41 | + "INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id", |
42 | + newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt) | ||
43 | + | ||
19 | Expect(err).NotTo(HaveOccurred()) | 44 | Expect(err).NotTo(HaveOccurred()) |
20 | }) | 45 | }) |
46 | + | ||
21 | Describe("设置公司管理员", func() { | 47 | Describe("设置公司管理员", func() { |
22 | Context("", func() { | 48 | Context("", func() { |
23 | It("", func() { | 49 | It("", func() { |
24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 50 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
25 | body := map[string]interface{}{ | 51 | body := map[string]interface{}{ |
26 | - "companyId": "int64", | ||
27 | - "userAccount": "string", | ||
28 | - "userName": "string", | 52 | + "companyId": newCompany.CompanyId, |
53 | + "userAccount": "userAccount", | ||
54 | + "userName": "userName", | ||
29 | } | 55 | } |
30 | - httpExpect.POST("/companys/setCompanyAdmin"). | 56 | + httpExpect.POST("/companies/setCompanyAdmin"). |
31 | WithJSON(body). | 57 | WithJSON(body). |
32 | Expect(). | 58 | Expect(). |
33 | Status(http.StatusOK). | 59 | Status(http.StatusOK). |
@@ -40,7 +66,7 @@ var _ = Describe("设置公司管理员", func() { | @@ -40,7 +66,7 @@ var _ = Describe("设置公司管理员", func() { | ||
40 | }) | 66 | }) |
41 | }) | 67 | }) |
42 | AfterEach(func() { | 68 | AfterEach(func() { |
43 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 69 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
44 | Expect(err).NotTo(HaveOccurred()) | 70 | Expect(err).NotTo(HaveOccurred()) |
45 | }) | 71 | }) |
46 | }) | 72 | }) |
1 | package company | 1 | package company |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
4 | "net/http" | 7 | "net/http" |
8 | + "time" | ||
5 | 9 | ||
6 | "github.com/gavv/httpexpect" | 10 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 11 | . "github.com/onsi/ginkgo" |
@@ -11,11 +15,32 @@ import ( | @@ -11,11 +15,32 @@ import ( | ||
11 | 15 | ||
12 | var _ = Describe("更新", func() { | 16 | var _ = Describe("更新", func() { |
13 | var companyId int64 | 17 | var companyId int64 |
18 | + var newCompany *domain.Company | ||
14 | BeforeEach(func() { | 19 | BeforeEach(func() { |
20 | + newCompany = &domain.Company{ | ||
21 | + CompanyId: GinkgoRandomSeed(), | ||
22 | + CompanyInfo: &domain.CompanyInfo{ | ||
23 | + Name: "公司名称", // 公司名称 | ||
24 | + Abbreviation: "公司简称", // 公司简称 | ||
25 | + Logo: "", // 公司logo | ||
26 | + Phone: "", // 公司联系电话 | ||
27 | + Status: 1, // 状态 1正常 2禁用 | ||
28 | + Remarks: "备注", // 备注 | ||
29 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
30 | + Admin: &domain.CompanyAdmin{ | ||
31 | + UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 | ||
32 | + UserName: "用户名称", // 用户名称 | ||
33 | + }, // 公司主管理员 | ||
34 | + }, | ||
35 | + CreateAt: time.Now(), | ||
36 | + UpdateAt: time.Now(), | ||
37 | + } | ||
38 | + | ||
15 | _, err := pG.DB.QueryOne( | 39 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(&companyId), | 40 | pg.Scan(&companyId), |
17 | - "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | - "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | 41 | + "INSERT INTO companies (company_id, company_info, create_at, update_at) VALUES (?, ?, ?, ?) RETURNING company_id", |
42 | + newCompany.CompanyId, newCompany.CompanyInfo, newCompany.CreateAt, newCompany.UpdateAt) | ||
43 | + | ||
19 | Expect(err).NotTo(HaveOccurred()) | 44 | Expect(err).NotTo(HaveOccurred()) |
20 | }) | 45 | }) |
21 | Describe("提交数据更新", func() { | 46 | Describe("提交数据更新", func() { |
@@ -25,12 +50,12 @@ var _ = Describe("更新", func() { | @@ -25,12 +50,12 @@ var _ = Describe("更新", func() { | ||
25 | body := map[string]interface{}{ | 50 | body := map[string]interface{}{ |
26 | "name": "string", | 51 | "name": "string", |
27 | "abbreviation": "string", | 52 | "abbreviation": "string", |
28 | - "status": "int64", | 53 | + "status": 1, |
29 | "remarks": "string", | 54 | "remarks": "string", |
30 | "userAccount": "string", | 55 | "userAccount": "string", |
31 | "userName": "string", | 56 | "userName": "string", |
32 | } | 57 | } |
33 | - httpExpect.PUT("/companys/{companyId}"). | 58 | + httpExpect.PUT("/companies/" + fmt.Sprint(GinkgoRandomSeed())). |
34 | WithJSON(body). | 59 | WithJSON(body). |
35 | Expect(). | 60 | Expect(). |
36 | Status(http.StatusOK). | 61 | Status(http.StatusOK). |
@@ -44,7 +69,7 @@ var _ = Describe("更新", func() { | @@ -44,7 +69,7 @@ var _ = Describe("更新", func() { | ||
44 | }) | 69 | }) |
45 | }) | 70 | }) |
46 | AfterEach(func() { | 71 | AfterEach(func() { |
47 | - _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | 72 | + _, err := pG.DB.Exec("DELETE FROM companies WHERE true") |
48 | Expect(err).NotTo(HaveOccurred()) | 73 | Expect(err).NotTo(HaveOccurred()) |
49 | }) | 74 | }) |
50 | }) | 75 | }) |
-
请 注册 或 登录 后发表评论