Skip to content

Commit

Permalink
Merge pull request #31 from ProjectBARO/feat/push-notification
Browse files Browse the repository at this point in the history
[close #28, close #30] ๋‹ค์–‘ํ•œ ์ž์„ธ ๋ถ„์„ ๊ฒฐ๊ณผ ์ถ”๊ฐ€ ๋ฐ ํ‘ธ์‹œ ์•Œ๋ฆผ ๊ธฐ๋Šฅ ๊ตฌํ˜„ (FCM)
  • Loading branch information
YehyeokBang authored Jan 30, 2024
2 parents 5131557 + 5510300 commit fb31530
Show file tree
Hide file tree
Showing 19 changed files with 1,469 additions and 266 deletions.
19 changes: 12 additions & 7 deletions app/report/models/Report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package models
import "time"

type Report struct {
ID uint `gorm:"primaryKey"`
UserID uint
AlertCount int
AnalysisTime int
Type string
Predict string
CreatedAt time.Time `gorm:"autoCreateTime"`
ID uint `gorm:"primaryKey"`
UserID uint
AlertCount int
AnalysisTime int
Type string
Predict string
NormalRatio string
Score string
NeckAngles string
Distances string
StatusFrequencies string
CreatedAt time.Time `gorm:"autoCreateTime"`
}
170 changes: 115 additions & 55 deletions app/report/repositories/report_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,23 @@ func TestReportrRepository_Save(t *testing.T) {

// Create sample report for the test
report := models.Report{
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Predict: "Good",
Type: "Study",
CreatedAt: time.Now(),
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Type: "Study",
Predict: "Good",
Score: "90.000",
NormalRatio: "90.000",
NeckAngles: "angle",
Distances: "distance",
StatusFrequencies: "status",
CreatedAt: time.Now(),
}

// Set up expectations for the mock DB to return the sample report
mock.ExpectBegin()
mock.ExpectExec("INSERT INTO `reports`").
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.CreatedAt).
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.Score, report.NormalRatio, report.NeckAngles, report.Distances, report.StatusFrequencies, report.CreatedAt).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

Expand All @@ -64,8 +69,14 @@ func TestReportrRepository_Save(t *testing.T) {
assert.Equal(t, report.UserID, createdReport.UserID)
assert.Equal(t, report.AlertCount, createdReport.AlertCount)
assert.Equal(t, report.AnalysisTime, createdReport.AnalysisTime)
assert.Equal(t, report.Predict, createdReport.Predict)
assert.Equal(t, report.Type, createdReport.Type)
assert.Equal(t, report.Predict, createdReport.Predict)
assert.Equal(t, report.Score, createdReport.Score)
assert.Equal(t, report.NormalRatio, createdReport.NormalRatio)
assert.Equal(t, report.NeckAngles, createdReport.NeckAngles)
assert.Equal(t, report.Distances, createdReport.Distances)
assert.Equal(t, report.StatusFrequencies, createdReport.StatusFrequencies)
assert.Equal(t, report.CreatedAt, createdReport.CreatedAt)
}

func TestReportRepository_Save_Error(t *testing.T) {
Expand All @@ -92,18 +103,23 @@ func TestReportRepository_Save_Error(t *testing.T) {

// Create sample report for the test
report := models.Report{
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Predict: "Good",
Type: "Study",
CreatedAt: time.Now(),
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Type: "Study",
Predict: "Good",
Score: "90.000",
NormalRatio: "90.000",
NeckAngles: "angle",
Distances: "distance",
StatusFrequencies: "status",
CreatedAt: time.Now(),
}

// Set up expectations for the mock DB to return the sample report
mock.ExpectBegin()
mock.ExpectExec("INSERT INTO `reports`").
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.CreatedAt).
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.Score, report.NormalRatio, report.NeckAngles, report.Distances, report.StatusFrequencies, report.CreatedAt).
WillReturnError(err)
mock.ExpectRollback()

Expand Down Expand Up @@ -141,18 +157,23 @@ func TestReportRepository_FindByUserID(t *testing.T) {

// Create sample report for the test
report := models.Report{
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Predict: "Good",
Type: "Study",
CreatedAt: time.Now(),
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Type: "Study",
Predict: "Good",
Score: "90.000",
NormalRatio: "90.000",
NeckAngles: "angle",
Distances: "distance",
StatusFrequencies: "status",
CreatedAt: time.Now(),
}

// Set up expectations for the mock DB to return the sample report
mock.ExpectBegin()
mock.ExpectExec("INSERT INTO `reports`").
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.CreatedAt).
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.Score, report.NormalRatio, report.NeckAngles, report.Distances, report.StatusFrequencies, report.CreatedAt).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

Expand All @@ -165,8 +186,8 @@ func TestReportRepository_FindByUserID(t *testing.T) {
// Set up expectations for the mock DB to return the sample report
mock.ExpectQuery("SELECT \\* FROM `reports` WHERE user_id = \\?").
WithArgs(report.UserID).
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.CreatedAt))
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "score", "normal_ratio", "neck_angles", "distances", "status_frequencies", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.Score, savedReport.NormalRatio, savedReport.NeckAngles, savedReport.Distances, savedReport.StatusFrequencies, savedReport.CreatedAt))

// Call the method under test
reports, err := reportRepository.FindByUserID(report.UserID)
Expand All @@ -181,8 +202,14 @@ func TestReportRepository_FindByUserID(t *testing.T) {
assert.Equal(t, savedReport.UserID, reports[0].UserID)
assert.Equal(t, savedReport.AlertCount, reports[0].AlertCount)
assert.Equal(t, savedReport.AnalysisTime, reports[0].AnalysisTime)
assert.Equal(t, savedReport.Predict, reports[0].Predict)
assert.Equal(t, savedReport.Type, reports[0].Type)
assert.Equal(t, savedReport.Predict, reports[0].Predict)
assert.Equal(t, savedReport.Score, reports[0].Score)
assert.Equal(t, savedReport.NormalRatio, reports[0].NormalRatio)
assert.Equal(t, savedReport.NeckAngles, reports[0].NeckAngles)
assert.Equal(t, savedReport.Distances, reports[0].Distances)
assert.Equal(t, savedReport.StatusFrequencies, reports[0].StatusFrequencies)
assert.Equal(t, savedReport.CreatedAt, reports[0].CreatedAt)
}

func TestReportRepository_FindByUserID_Error(t *testing.T) {
Expand Down Expand Up @@ -245,18 +272,23 @@ func TestReportRepository_FindById(t *testing.T) {

// Create sample report for the test
report := models.Report{
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Predict: "Good",
Type: "Study",
CreatedAt: time.Now(),
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Type: "Study",
Predict: "Good",
Score: "90.000",
NormalRatio: "90.000",
NeckAngles: "angle",
Distances: "distance",
StatusFrequencies: "status",
CreatedAt: time.Now(),
}

// Set up expectations for the mock DB to return the sample report
mock.ExpectBegin()
mock.ExpectExec("INSERT INTO `reports`").
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.CreatedAt).
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.Score, report.NormalRatio, report.NeckAngles, report.Distances, report.StatusFrequencies, report.CreatedAt).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

Expand All @@ -269,8 +301,8 @@ func TestReportRepository_FindById(t *testing.T) {
// Set up expectations for the mock DB to return the sample report
mock.ExpectQuery("SELECT \\* FROM `reports` WHERE id = \\?").
WithArgs(savedReport.ID).
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.CreatedAt))
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "score", "normal_ratio", "neck_angles", "distances", "status_frequencies", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.Score, savedReport.NormalRatio, savedReport.NeckAngles, savedReport.Distances, savedReport.StatusFrequencies, savedReport.CreatedAt))

// Call the method under test
report, err = reportRepository.FindById(savedReport.ID)
Expand All @@ -285,8 +317,14 @@ func TestReportRepository_FindById(t *testing.T) {
assert.Equal(t, savedReport.UserID, report.UserID)
assert.Equal(t, savedReport.AlertCount, report.AlertCount)
assert.Equal(t, savedReport.AnalysisTime, report.AnalysisTime)
assert.Equal(t, savedReport.Predict, report.Predict)
assert.Equal(t, savedReport.Type, report.Type)
assert.Equal(t, savedReport.Predict, report.Predict)
assert.Equal(t, savedReport.Score, report.Score)
assert.Equal(t, savedReport.NormalRatio, report.NormalRatio)
assert.Equal(t, savedReport.NeckAngles, report.NeckAngles)
assert.Equal(t, savedReport.Distances, report.Distances)
assert.Equal(t, savedReport.StatusFrequencies, report.StatusFrequencies)
assert.Equal(t, savedReport.CreatedAt, report.CreatedAt)
}

func TestReportRepository_FindById_Error(t *testing.T) {
Expand Down Expand Up @@ -348,18 +386,23 @@ func TestReportRepository_FindByYearAndMonth(t *testing.T) {

// Create sample report for the test
report := models.Report{
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Predict: "Good",
Type: "Study",
CreatedAt: time.Now(),
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Type: "Study",
Predict: "Good",
Score: "90.000",
NormalRatio: "90.000",
NeckAngles: "angle",
Distances: "distance",
StatusFrequencies: "status",
CreatedAt: time.Now(),
}

// Set up expectations for the mock DB to return the sample report
mock.ExpectBegin()
mock.ExpectExec("INSERT INTO `reports`").
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.CreatedAt).
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.Score, report.NormalRatio, report.NeckAngles, report.Distances, report.StatusFrequencies, report.CreatedAt).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

Expand All @@ -375,8 +418,8 @@ func TestReportRepository_FindByYearAndMonth(t *testing.T) {
// Set up expectations for the mock DB to return the sample report
mock.ExpectQuery("SELECT \\* FROM `reports` WHERE user_id = \\? AND DATE_FORMAT\\(created_at, '%Y%m'\\) = \\?").
WithArgs(savedReport.UserID, yearAndMonth).
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.CreatedAt))
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "score", "normal_ratio", "neck_angles", "distances", "status_frequencies", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.Score, savedReport.NormalRatio, savedReport.NeckAngles, savedReport.Distances, savedReport.StatusFrequencies, savedReport.CreatedAt))

// Call the method under test
reports, err := reportRepository.FindByYearAndMonth(savedReport.UserID, yearAndMonth)
Expand All @@ -391,8 +434,14 @@ func TestReportRepository_FindByYearAndMonth(t *testing.T) {
assert.Equal(t, savedReport.UserID, reports[0].UserID)
assert.Equal(t, savedReport.AlertCount, reports[0].AlertCount)
assert.Equal(t, savedReport.AnalysisTime, reports[0].AnalysisTime)
assert.Equal(t, savedReport.Predict, reports[0].Predict)
assert.Equal(t, savedReport.Type, reports[0].Type)
assert.Equal(t, savedReport.Predict, reports[0].Predict)
assert.Equal(t, savedReport.Score, reports[0].Score)
assert.Equal(t, savedReport.NormalRatio, reports[0].NormalRatio)
assert.Equal(t, savedReport.NeckAngles, reports[0].NeckAngles)
assert.Equal(t, savedReport.Distances, reports[0].Distances)
assert.Equal(t, savedReport.StatusFrequencies, reports[0].StatusFrequencies)
assert.Equal(t, savedReport.CreatedAt, reports[0].CreatedAt)
}

func TestReportRepository_FindByYearAndMonth_Error(t *testing.T) {
Expand Down Expand Up @@ -457,18 +506,23 @@ func TestReportRepository_FindAll(t *testing.T) {

// Create sample report for the test
report := models.Report{
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Predict: "Good",
Type: "Study",
CreatedAt: time.Now(),
UserID: 1,
AlertCount: 30,
AnalysisTime: 3600,
Type: "Study",
Predict: "Good",
Score: "90.000",
NormalRatio: "90.000",
NeckAngles: "angle",
Distances: "distance",
StatusFrequencies: "status",
CreatedAt: time.Now(),
}

// Set up expectations for the mock DB to return the sample report
mock.ExpectBegin()
mock.ExpectExec("INSERT INTO `reports`").
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.CreatedAt).
WithArgs(report.UserID, report.AlertCount, report.AnalysisTime, report.Type, report.Predict, report.Score, report.NormalRatio, report.NeckAngles, report.Distances, report.StatusFrequencies, report.CreatedAt).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

Expand All @@ -480,8 +534,8 @@ func TestReportRepository_FindAll(t *testing.T) {

// Set up expectations for the mock DB to return the sample report
mock.ExpectQuery("SELECT \\* FROM `reports`").
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.CreatedAt))
WillReturnRows(sqlmock.NewRows([]string{"id", "user_id", "alert_count", "analysis_time", "type", "predict", "score", "normal_ratio", "neck_angles", "distances", "status_frequencies", "created_at"}).
AddRow(savedReport.ID, savedReport.UserID, savedReport.AlertCount, savedReport.AnalysisTime, savedReport.Type, savedReport.Predict, savedReport.Score, savedReport.NormalRatio, savedReport.NeckAngles, savedReport.Distances, savedReport.StatusFrequencies, savedReport.CreatedAt))

// Call the method under test
reports, err := reportRepository.FindAll()
Expand All @@ -496,8 +550,14 @@ func TestReportRepository_FindAll(t *testing.T) {
assert.Equal(t, savedReport.UserID, reports[0].UserID)
assert.Equal(t, savedReport.AlertCount, reports[0].AlertCount)
assert.Equal(t, savedReport.AnalysisTime, reports[0].AnalysisTime)
assert.Equal(t, savedReport.Predict, reports[0].Predict)
assert.Equal(t, savedReport.Type, reports[0].Type)
assert.Equal(t, savedReport.Predict, reports[0].Predict)
assert.Equal(t, savedReport.Score, reports[0].Score)
assert.Equal(t, savedReport.NormalRatio, reports[0].NormalRatio)
assert.Equal(t, savedReport.NeckAngles, reports[0].NeckAngles)
assert.Equal(t, savedReport.Distances, reports[0].Distances)
assert.Equal(t, savedReport.StatusFrequencies, reports[0].StatusFrequencies)
assert.Equal(t, savedReport.CreatedAt, reports[0].CreatedAt)
}

func TestReportRepository_FindAll_Error(t *testing.T) {
Expand Down
Loading

0 comments on commit fb31530

Please sign in to comment.