Conversation
|
Thanks, will check it. |
notification/application_test.go
Outdated
| mockDB := mocksdb.NewDB(s.T()) | ||
| s.mockConfig.EXPECT().GetString("DB_CONNECTION").Return("mysql").Once() | ||
| mockDB.EXPECT().Connection("mysql").Return(mockDB).Once() | ||
| mockDB.EXPECT().Table("notifications").Return(nil).Once() |
There was a problem hiding this comment.
mockQuery should be returned here, then mockQuery.EXPECT().Insert().
| mockDB.EXPECT().Table("notifications").Return(mockQuery).Once() | ||
|
|
||
| var notificationModel models.Notification | ||
| notificationModel.ID = uuid.New().String() |
There was a problem hiding this comment.
@hwbrzzl
Random UUIDs causing test failures, how to handle?
=== RUN TestApplicationTestSuite
=== RUN TestApplicationTestSuite/TestDatabaseNotification
mock.go:361:
mock: Unexpected Method Call
-----------------------------
Insert(*models.Notification)
0: &models.Notification{ID:"f6ddac72-b09c-47b4-baf4-f0c351530f5f", Type:"notification.LoginSuccessNotification", NotifiableType:"notification.User", NotifiableId:"1", Data:"{\"content\":\"Congratulations, your login is successful!\",\"title\":\"Login success\"}", ReadAt:<nil>, Timestamps:orm.Timestamps{CreatedAt:<nil>, UpdatedAt:<nil>}}
The closest call I have is:
Insert(*models.Notification)
0: &models.Notification{ID:"bb39e579-17f2-4299-a91f-fc2eb45ce293", Type:"notification.LoginSuccessNotification", NotifiableType:"notification.User", NotifiableId:"1", Data:"{\"content\":\"Congratulations, your login is successful!\",\"title\":\"Login success\"}", ReadAt:<nil>, Timestamps:orm.Timestamps{CreatedAt:<nil>, UpdatedAt:<nil>}}
Difference found in argument 0:
--- Expected
+++ Actual
@@ -1,3 +1,3 @@
(*models.Notification)({
- ID: (string) (len=36) "bb39e579-17f2-4299-a91f-fc2eb45ce293",
+ ID: (string) (len=36) "f6ddac72-b09c-47b4-baf4-f0c351530f5f",
Type: (string) (len=37) "notification.LoginSuccessNotification",
Diff: 0: FAIL: (*models.Notification=&{f6ddac72-b09c-47b4-baf4-f0c351530f5f notification.LoginSuccessNotification notification.User 1 {"content":"Congratulations, your login is successful!","title":"Login success"} { }}) != (*models.Notification=&{bb39e579-17f2-4299-a91f-fc2eb45ce293 notification.LoginSuccessNotification notification.User 1 {"content":"Congratulations, your login is successful!","title":"Login success"} { }})
at: [D:/work/study/goravel/framework/mocks/database/db/Query.go:1142 D:/work/study/goravel/framework/notification/channels/database.go:34 D:/work/study/goravel/framework/notification/application.go:51 D:/work/study/goravel/framework/notification/application_test.go:146]
Query.go:4259: FAIL: Insert(*models.Notification)
at: [D:/work/study/goravel/framework/mocks/database/db/Query.go:1178 D:/work/study/goravel/framework/notification/application_test.go:139]
Query.go:4259: FAIL: 0 out of 1 expectation(s) were met.
The code you are testing needs to make 1 more call(s).
at: [D:/work/study/goravel/framework/mocks/database/db/Query.go:4259 D:/work/program/GoEnvironment/g/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.4.windows-amd64/src/testing/testing.go:1308 D:/work/program/GoEnvironment/g/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.4.windows-amd64/src/testing/testing.go:1572 D:/work/program/GoEnvironment/g/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.4.windows-amd64/src/testing/testing.go:1928 D:/work/program/GoEnvironment/g/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.4.windows-amd64/src/runtime/panic.go:615 D:/work/program/GoEnvironment/g/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.4.windows-amd64/src/testing/testing.go:1013 D:/work/study/goravel/framework/mocks/database/db/Query.go:1142 D:/work/study/goravel/framework/notification/channels/database.go:34 D:/work/study/goravel/framework/notification/application.go:51 D:/work/study/goravel/framework/notification/application_test.go:146]
--- FAIL: TestApplicationTestSuite/TestDatabaseNotification (0.00s)
--- FAIL: TestApplicationTestSuite (0.00s)
FAIL
There was a problem hiding this comment.
|
@hwbrzzl
|
Could you relate your questions to the specific code? |
|
@hwbrzzl I have solved these two problems. I will submit my code later. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1271 +/- ##
==========================================
- Coverage 68.47% 67.42% -1.05%
==========================================
Files 264 271 +7
Lines 15493 15606 +113
==========================================
- Hits 10609 10523 -86
- Misses 4406 4626 +220
+ Partials 478 457 -21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @wuzhixiang0827 Could you add the use cases in the PR description? Let's confirm the basic logic first before a deeper optimization. |
Sure, I will add it later. |

notification开发过程中几个问题.docx
@hwbrzzl Several questions during the development of notifications, please provide answers.