正在显示
12 个修改的文件
包含
355 行增加
和
23 行删除
deploy/k8s/test/.gitkeep
已删除
100644 → 0
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetOffTaskRecordQuery struct { | ||
10 | + // 关闭任务记录ID | ||
11 | + OffTaskRecordId int64 `json:"offTaskRecordId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getOffTaskRecordQuery *GetOffTaskRecordQuery) ValidateQuery() error { | ||
15 | + valid := validation.Validation{} | ||
16 | + b, err := valid.Valid(getOffTaskRecordQuery) | ||
17 | + if err != nil { | ||
18 | + return err | ||
19 | + } | ||
20 | + if !b { | ||
21 | + for _, validErr := range valid.Errors { | ||
22 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
23 | + } | ||
24 | + } | ||
25 | + return nil | ||
26 | +} |
@@ -284,8 +284,8 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask | @@ -284,8 +284,8 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask | ||
284 | } | 284 | } |
285 | 285 | ||
286 | // 搜索关闭任务记录 | 286 | // 搜索关闭任务记录 |
287 | -func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecord *command.SearchTaskCommand) (interface{}, error) { | ||
288 | - if err := searchOffTaskRecord.ValidateCommand(); err != nil { | 287 | +func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *command.SearchOffTaskRecordCommand) (interface{}, error) { |
288 | + if err := searchOffTaskRecordCommand.ValidateCommand(); err != nil { | ||
289 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 289 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
290 | } | 290 | } |
291 | transactionContext, err := factory.CreateTransactionContext(nil) | 291 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -306,7 +306,39 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecord *command | @@ -306,7 +306,39 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecord *command | ||
306 | } else { | 306 | } else { |
307 | taskRepository = value | 307 | taskRepository = value |
308 | } | 308 | } |
309 | - if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchOffTaskRecord)); err != nil { | 309 | + var offTaskRecordRepository domain.OffTaskRecordRepository |
310 | + if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{ | ||
311 | + "transactionContext": transactionContext, | ||
312 | + }); err != nil { | ||
313 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
314 | + } else { | ||
315 | + offTaskRecordRepository = value | ||
316 | + } | ||
317 | + _, tasks, err := taskRepository.Find(map[string]interface{}{ | ||
318 | + "companyId": searchOffTaskRecordCommand.CompanyId, | ||
319 | + "taskStatus": domain.TASK_STATUS_CLOSED, | ||
320 | + "taskContentMatch": searchOffTaskRecordCommand.TaskContentMatch, | ||
321 | + "taskType": searchOffTaskRecordCommand.TaskType, | ||
322 | + "customerValue": searchOffTaskRecordCommand.CustomerValue, | ||
323 | + "taskNature": searchOffTaskRecordCommand.TaskNature, | ||
324 | + "offset": searchOffTaskRecordCommand.Offset, | ||
325 | + "limit": searchOffTaskRecordCommand.Limit, | ||
326 | + }) | ||
327 | + if err != nil { | ||
328 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
329 | + } | ||
330 | + fmt.Println(tasks) | ||
331 | + var taskIds []int64 | ||
332 | + for _, task := range tasks { | ||
333 | + taskIds = append(taskIds, task.TaskId) | ||
334 | + } | ||
335 | + if count, offTaskRecords, err := offTaskRecordRepository.Find(map[string]interface{}{ | ||
336 | + "taskIds": taskIds, | ||
337 | + "customerValue": searchOffTaskRecordCommand.CustomerValue, | ||
338 | + "offStartTime": searchOffTaskRecordCommand.OffStartTime, | ||
339 | + "offEndTime": searchOffTaskRecordCommand.OffEndTime, | ||
340 | + "limit": searchOffTaskRecordCommand.Limit, | ||
341 | + }); err != nil { | ||
310 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 342 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
311 | } else { | 343 | } else { |
312 | if err := transactionContext.CommitTransaction(); err != nil { | 344 | if err := transactionContext.CommitTransaction(); err != nil { |
@@ -314,11 +346,48 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecord *command | @@ -314,11 +346,48 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecord *command | ||
314 | } | 346 | } |
315 | return map[string]interface{}{ | 347 | return map[string]interface{}{ |
316 | "count": count, | 348 | "count": count, |
317 | - "tasks": tasks, | 349 | + "offTaskRecords": offTaskRecords, |
318 | }, nil | 350 | }, nil |
319 | } | 351 | } |
320 | } | 352 | } |
321 | 353 | ||
354 | +// 返回关闭任务记录 | ||
355 | +func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.GetOffTaskRecordQuery) (interface{}, error) { | ||
356 | + if err := getOffTaskRecordQuery.ValidateQuery(); err != nil { | ||
357 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
358 | + } | ||
359 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
360 | + if err != nil { | ||
361 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
362 | + } | ||
363 | + if err := transactionContext.StartTransaction(); err != nil { | ||
364 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
365 | + } | ||
366 | + defer func() { | ||
367 | + transactionContext.RollbackTransaction() | ||
368 | + }() | ||
369 | + var offTaskRecordRepository domain.OffTaskRecordRepository | ||
370 | + if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{ | ||
371 | + "transactionContext": transactionContext, | ||
372 | + }); err != nil { | ||
373 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
374 | + } else { | ||
375 | + offTaskRecordRepository = value | ||
376 | + } | ||
377 | + offTaskRecord, err := offTaskRecordRepository.FindOne(map[string]interface{}{"offTaskRecordId": getOffTaskRecordQuery.OffTaskRecordId}) | ||
378 | + if err != nil { | ||
379 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
380 | + } | ||
381 | + if offTaskRecord == nil { | ||
382 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getOffTaskRecordQuery.OffTaskRecordId))) | ||
383 | + } else { | ||
384 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
385 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
386 | + } | ||
387 | + return offTaskRecord, nil | ||
388 | + } | ||
389 | +} | ||
390 | + | ||
322 | // 创建新任务 | 391 | // 创建新任务 |
323 | func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) { | 392 | func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) { |
324 | if err := createTaskCommand.ValidateCommand(); err != nil { | 393 | if err := createTaskCommand.ValidateCommand(); err != nil { |
@@ -8,4 +8,6 @@ type TaskPercentageItem struct { | @@ -8,4 +8,6 @@ type TaskPercentageItem struct { | ||
8 | Percentage int `json:"percentage"` | 8 | Percentage int `json:"percentage"` |
9 | // 分配到的奖励素币 | 9 | // 分配到的奖励素币 |
10 | SuMoney float64 `json:"suMoney"` | 10 | SuMoney float64 `json:"suMoney"` |
11 | + // 分配到的奖励素币 | ||
12 | + IssueScore float64 `json:"issueScore"` | ||
11 | } | 13 | } |
@@ -63,7 +63,7 @@ func (service *ExchangeSuMoneyService) Exchange(uid int64, operatorUid int64, su | @@ -63,7 +63,7 @@ func (service *ExchangeSuMoneyService) Exchange(uid int64, operatorUid int64, su | ||
63 | RecordDescription: recordDescription, | 63 | RecordDescription: recordDescription, |
64 | CreateTime: time.Now(), | 64 | CreateTime: time.Now(), |
65 | } | 65 | } |
66 | - if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, suMoney); err != nil { | 66 | + if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, 0 - suMoney); err != nil { |
67 | return nil, err | 67 | return nil, err |
68 | } | 68 | } |
69 | if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil { | 69 | if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil { |
@@ -2,11 +2,11 @@ package repository | @@ -2,11 +2,11 @@ package repository | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - | ||
6 | "github.com/go-pg/pg" | 5 | "github.com/go-pg/pg" |
7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" |
9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models" | 8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models" |
9 | + "time" | ||
10 | ) | 10 | ) |
11 | 11 | ||
12 | type OffTaskRecordRepository struct { | 12 | type OffTaskRecordRepository struct { |
@@ -66,8 +66,14 @@ func (repository *OffTaskRecordRepository) Find(queryOptions map[string]interfac | @@ -66,8 +66,14 @@ func (repository *OffTaskRecordRepository) Find(queryOptions map[string]interfac | ||
66 | var offTaskRecordModels []*models.OffTaskRecord | 66 | var offTaskRecordModels []*models.OffTaskRecord |
67 | offTaskRecords := make([]*domain.OffTaskRecord, 0) | 67 | offTaskRecords := make([]*domain.OffTaskRecord, 0) |
68 | query := tx.Model(&offTaskRecordModels) | 68 | query := tx.Model(&offTaskRecordModels) |
69 | - if offTaskRecordIds, ok := queryOptions["offTaskRecordIds"]; ok { | ||
70 | - query = query.Where(`off_task_record.task_id IN (?)`, pg.In(offTaskRecordIds.([]int64))) | 69 | + if taskIds, ok := queryOptions["taskIds"]; ok && len(taskIds.([]int64)) > 0 { |
70 | + query = query.Where(`off_task_record.task_id IN (?)`, pg.In(taskIds.([]int64))) | ||
71 | + } | ||
72 | + if offStartTime, ok := queryOptions["offStartTime"]; ok && !offStartTime.(time.Time).IsZero() { | ||
73 | + query = query.Where(`off_task_record.create_time > ?`, offStartTime) | ||
74 | + } | ||
75 | + if offEndTime, ok := queryOptions["offEndTime"]; ok && !offEndTime.(time.Time).IsZero() { | ||
76 | + query = query.Where(`off_task_record.create_time < ?`, offEndTime) | ||
71 | } | 77 | } |
72 | if offset, ok := queryOptions["offset"]; ok { | 78 | if offset, ok := queryOptions["offset"]; ok { |
73 | offset := offset.(int) | 79 | offset := offset.(int) |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + | ||
6 | + "github.com/astaxie/beego" | ||
7 | + "github.com/linmadan/egglib-go/web/beego/utils" | ||
8 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command" | ||
9 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query" | ||
10 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/service" | ||
11 | +) | ||
12 | + | ||
13 | +type OffTaskRecordController struct { | ||
14 | + beego.Controller | ||
15 | +} | ||
16 | + | ||
17 | +func (controller *OffTaskRecordController) GetOffTaskRecord() { | ||
18 | + taskService := service.NewTaskService(nil) | ||
19 | + getOffTaskRecordQuery := &query.GetOffTaskRecordQuery{} | ||
20 | + offTaskRecordId, _ := controller.GetInt64(":offTaskRecordId") | ||
21 | + getOffTaskRecordQuery.OffTaskRecordId = offTaskRecordId | ||
22 | + data, err := taskService.GetOffTaskRecord(getOffTaskRecordQuery) | ||
23 | + var response utils.JsonResponse | ||
24 | + if err != nil { | ||
25 | + response = utils.ResponseError(controller.Ctx, err) | ||
26 | + } else { | ||
27 | + response = utils.ResponseData(controller.Ctx, data) | ||
28 | + } | ||
29 | + controller.Data["json"] = response | ||
30 | + controller.ServeJSON() | ||
31 | +} | ||
32 | + | ||
33 | +func (controller *OffTaskRecordController) SearchOffTaskRecord() { | ||
34 | + taskService := service.NewTaskService(nil) | ||
35 | + searchOffTaskRecordCommand := &command.SearchOffTaskRecordCommand{} | ||
36 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchOffTaskRecordCommand) | ||
37 | + data, err := taskService.SearchOffTaskRecord(searchOffTaskRecordCommand) | ||
38 | + var response utils.JsonResponse | ||
39 | + if err != nil { | ||
40 | + response = utils.ResponseError(controller.Ctx, err) | ||
41 | + } else { | ||
42 | + response = utils.ResponseData(controller.Ctx, data) | ||
43 | + } | ||
44 | + controller.Data["json"] = response | ||
45 | + controller.ServeJSON() | ||
46 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/astaxie/beego" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + beego.Router("/off-task-records/:offTaskRecordId", &controllers.OffTaskRecordController{}, "Get:GetOffTaskRecord") | ||
10 | + beego.Router("/off-task-records/search-off-task-record", &controllers.OffTaskRecordController{}, "Post:SearchOffTaskRecord") | ||
11 | +} |
1 | +package off_task_record | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
5 | + "net/http" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/gavv/httpexpect" | ||
9 | + "github.com/go-pg/pg" | ||
10 | + . "github.com/onsi/ginkgo" | ||
11 | + . "github.com/onsi/gomega" | ||
12 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
13 | +) | ||
14 | + | ||
15 | +var _ = Describe("返回关闭任务记录", func() { | ||
16 | + BeforeEach(func() { | ||
17 | + _, err := pG.DB.QueryOne( | ||
18 | + pg.Scan(), | ||
19 | + "INSERT INTO off_task_records (id, task_id, operator, off_reason, create_time) VALUES (?, ?, ?, ?, ?)", | ||
20 | + 1, 1, &domain.EmployeeInfo{ | ||
21 | + Uid: 2499036607974745088, | ||
22 | + }, "testOffReason", time.Now()) | ||
23 | + Expect(err).NotTo(HaveOccurred()) | ||
24 | + }) | ||
25 | + Describe("返回关闭任务记录", func() { | ||
26 | + Context("传入有效的offTaskRecordId", func() { | ||
27 | + It("返回关闭任务记录", func() { | ||
28 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
29 | + httpExpect.GET("/off-task-records/1"). | ||
30 | + Expect(). | ||
31 | + Status(http.StatusOK). | ||
32 | + JSON(). | ||
33 | + Object(). | ||
34 | + ContainsKey("code").ValueEqual("code", 0). | ||
35 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
36 | + ContainsKey("data").Value("data").Object() | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM off_task_records WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
1 | +package off_task_record | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/astaxie/beego" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestOffTaskRecord(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port OffTaskRecord Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = beego.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package off_task_record | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
5 | + "net/http" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/gavv/httpexpect" | ||
9 | + "github.com/go-pg/pg" | ||
10 | + . "github.com/onsi/ginkgo" | ||
11 | + . "github.com/onsi/gomega" | ||
12 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
13 | +) | ||
14 | + | ||
15 | +var _ = Describe("搜索关闭任务记录", func() { | ||
16 | + var offTaskRecordId int64 | ||
17 | + BeforeEach(func() { | ||
18 | + _, err := pG.DB.QueryOne( | ||
19 | + pg.Scan(&offTaskRecordId), | ||
20 | + "INSERT INTO off_task_records (id, task_id, operator, off_reason, create_time) VALUES (?, ?, ?, ?, ?) RETURNING id", | ||
21 | + 1, 1, &domain.EmployeeInfo{ | ||
22 | + Uid: 2499036607974745088, | ||
23 | + }, "testOffReason", time.Now()) | ||
24 | + Expect(err).NotTo(HaveOccurred()) | ||
25 | + dayAfter, _ := time.ParseDuration("72h") | ||
26 | + _, err1 := pG.DB.QueryOne( | ||
27 | + pg.Scan(), | ||
28 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
29 | + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{ | ||
30 | + Uid: 2499036607974745088, | ||
31 | + }, 6, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{ | ||
32 | + { | ||
33 | + Uid: 2499036607974745077, | ||
34 | + }, | ||
35 | + { | ||
36 | + Uid: 2499036607974745066, | ||
37 | + }, | ||
38 | + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter)) | ||
39 | + Expect(err1).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | + Describe("搜索关闭任务记录", func() { | ||
42 | + Context("", func() { | ||
43 | + It("", func() { | ||
44 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
45 | + body := map[string]interface{}{ | ||
46 | + "companyId": 101, | ||
47 | + "taskContentMatch": "", | ||
48 | + "taskType": 1, | ||
49 | + "customerValue": "", | ||
50 | + "taskNature": "", | ||
51 | + "offStartTime": time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), | ||
52 | + "offEndTime": time.Time{}, | ||
53 | + "offset": 0, | ||
54 | + "limit": 20, | ||
55 | + } | ||
56 | + httpExpect.POST("/off-task-records/search-off-task-record"). | ||
57 | + WithJSON(body). | ||
58 | + Expect(). | ||
59 | + Status(http.StatusOK). | ||
60 | + JSON(). | ||
61 | + Object(). | ||
62 | + ContainsKey("code").ValueEqual("code", 0). | ||
63 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
64 | + ContainsKey("data").Value("data").Object() | ||
65 | + }) | ||
66 | + }) | ||
67 | + }) | ||
68 | + AfterEach(func() { | ||
69 | + _, err := pG.DB.Exec("DELETE FROM off_task_records WHERE true") | ||
70 | + Expect(err).NotTo(HaveOccurred()) | ||
71 | + _, err1 := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
72 | + Expect(err1).NotTo(HaveOccurred()) | ||
73 | + }) | ||
74 | +}) |
1 | package su_money | 1 | package su_money |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "net/http" | ||
5 | - | ||
6 | "github.com/gavv/httpexpect" | 4 | "github.com/gavv/httpexpect" |
7 | "github.com/go-pg/pg" | 5 | "github.com/go-pg/pg" |
8 | . "github.com/onsi/ginkgo" | 6 | . "github.com/onsi/ginkgo" |
9 | . "github.com/onsi/gomega" | 7 | . "github.com/onsi/gomega" |
10 | pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | 8 | pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" |
9 | + "net/http" | ||
11 | ) | 10 | ) |
12 | 11 | ||
13 | var _ = Describe("素币兑换", func() { | 12 | var _ = Describe("素币兑换", func() { |
14 | - var suMoneyTransactionRecordId int64 | ||
15 | BeforeEach(func() { | 13 | BeforeEach(func() { |
16 | - _, err := pG.DB.QueryOne( | ||
17 | - pg.Scan(&suMoneyTransactionRecordId), | ||
18 | - "INSERT INTO su_money_transaction_records (su_money_transaction_record_id, record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | - "testSuMoneyTransactionRecordId", "testRecordType", "testEmployee", "testSuMoney", "testOperator", "testRecordDescription", "testCreateTime") | ||
20 | - Expect(err).NotTo(HaveOccurred()) | 14 | + _, err1 := pG.DB.QueryOne( |
15 | + pg.Scan(), | ||
16 | + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | ||
17 | + 1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 100.00) | ||
18 | + Expect(err1).NotTo(HaveOccurred()) | ||
19 | + _, err2 := pG.DB.QueryOne( | ||
20 | + pg.Scan(), | ||
21 | + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | ||
22 | + 2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0) | ||
23 | + Expect(err2).NotTo(HaveOccurred()) | ||
21 | }) | 24 | }) |
22 | Describe("素币兑换", func() { | 25 | Describe("素币兑换", func() { |
23 | - Context("", func() { | ||
24 | - It("", func() { | 26 | + Context("员工提交正确的数据兑换素币", func() { |
27 | + It("兑换成功", func() { | ||
25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 28 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
26 | body := map[string]interface{}{ | 29 | body := map[string]interface{}{ |
27 | - "uid": "int64", | ||
28 | - "suMoney": "float64", | ||
29 | - "operator": "int64", | ||
30 | - "exchangeDescription": "string", | 30 | + "uid": 2499036607974745088, |
31 | + "suMoney": 50, | ||
32 | + "operator": 2499036607974745099, | ||
33 | + "exchangeDescription": "兑换说明", | ||
31 | } | 34 | } |
32 | httpExpect.POST("/su-money/exchange"). | 35 | httpExpect.POST("/su-money/exchange"). |
33 | WithJSON(body). | 36 | WithJSON(body). |
@@ -40,9 +43,30 @@ var _ = Describe("素币兑换", func() { | @@ -40,9 +43,30 @@ var _ = Describe("素币兑换", func() { | ||
40 | ContainsKey("data").Value("data").Object() | 43 | ContainsKey("data").Value("data").Object() |
41 | }) | 44 | }) |
42 | }) | 45 | }) |
46 | + Context("员工提交超出现有素币的兑换素币请求", func() { | ||
47 | + It("兑换失败", func() { | ||
48 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
49 | + body := map[string]interface{}{ | ||
50 | + "uid": 2499036607974745088, | ||
51 | + "suMoney": 150, | ||
52 | + "operator": 2499036607974745099, | ||
53 | + "exchangeDescription": "兑换说明", | ||
54 | + } | ||
55 | + httpExpect.POST("/su-money/exchange"). | ||
56 | + WithJSON(body). | ||
57 | + Expect(). | ||
58 | + Status(http.StatusOK). | ||
59 | + JSON(). | ||
60 | + Object(). | ||
61 | + ContainsKey("code").ValueEqual("code", 501). | ||
62 | + ContainsKey("msg").ValueEqual("msg", "内部服务出错:当前素币不足") | ||
63 | + }) | ||
64 | + }) | ||
43 | }) | 65 | }) |
44 | AfterEach(func() { | 66 | AfterEach(func() { |
45 | - _, err := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true") | 67 | + _, err := pG.DB.Exec("DELETE FROM employees WHERE true") |
46 | Expect(err).NotTo(HaveOccurred()) | 68 | Expect(err).NotTo(HaveOccurred()) |
69 | + _, err1 := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true") | ||
70 | + Expect(err1).NotTo(HaveOccurred()) | ||
47 | }) | 71 | }) |
48 | }) | 72 | }) |
-
请 注册 或 登录 后发表评论