Skip to content

Commit

Permalink
improving meta data testing
Browse files Browse the repository at this point in the history
  • Loading branch information
niclasheun committed Dec 4, 2024
1 parent f603c1e commit 256c9ac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
24 changes: 23 additions & 1 deletion server/coursePhase/coursePhaseParticipation/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,29 @@ func (suite *CoursePhaseParticipationTestSuite) TestUpdateCoursePhaseParticipati
assert.Equal(suite.T(), updatedParticipation.ID, result.ID, "Participation ID should match")
assert.Equal(suite.T(), updatedParticipation.Passed, result.Passed, "Passed data should match")
assert.Equal(suite.T(), updatedParticipation.MetaData["other-value"], result.MetaData["other-value"], "New Meta data should match")
assert.Equal(suite.T(), "none", result.MetaData["skills"], "Old Meta data should be unaffected - Meta data was not appended")
assert.Equal(suite.T(), meta.MetaData{"skills": "none", "other-value": "some skills"}, result.MetaData, "Old Meta data should be unaffected - Meta data was not appended")
}

func (suite *CoursePhaseParticipationTestSuite) TestUpdateCoursePhaseParticipationWithMetaDataOverride() {
// Replace with a valid participation ID from your dump
participationID := uuid.MustParse("7698f081-df55-4136-a58c-1a166bb1bbda")
jsonData := `{"skills": "more than none", "other-value": "some skills"}`
// MetaData initialisieren
var metaData meta.MetaData
err := json.Unmarshal([]byte(jsonData), &metaData)
assert.NoError(suite.T(), err)

updatedParticipation := coursePhaseParticipationDTO.UpdateCoursePhaseParticipation{
ID: participationID,
MetaData: metaData,
Passed: pgtype.Bool{Bool: true, Valid: true},
}

result, err := UpdateCoursePhaseParticipation(suite.ctx, updatedParticipation)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), updatedParticipation.ID, result.ID, "Participation ID should match")
assert.Equal(suite.T(), updatedParticipation.Passed, result.Passed, "Passed data should match")
assert.Equal(suite.T(), updatedParticipation.MetaData, result.MetaData, "New Meta data should match")
}

func TestCoursePhaseParticipationTestSuite(t *testing.T) {
Expand Down
27 changes: 26 additions & 1 deletion server/coursePhase/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,32 @@ func (suite *CoursePhaseTestSuite) TestUpdateCoursePhase() {
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), "Updated Phase", updatedCoursePhase.Name, "Expected updated course phase name to match")
assert.False(suite.T(), updatedCoursePhase.IsInitialPhase, "Expected updated course phase to be an initial phase")
assert.Equal(suite.T(), metaData, updatedCoursePhase.MetaData, "Expected metadata to match updated data")
assert.Equal(suite.T(), meta.MetaData{"test-key": "test-value", "updated_key": "updated_value"}, updatedCoursePhase.MetaData, "Expected metadata to match updated data including the old data")
}

func (suite *CoursePhaseTestSuite) TestUpdateCoursePhaseWithMetaDataOverride() {
id := uuid.MustParse("3d1f3b00-87f3-433b-a713-178c4050411b")
jsonData := `{"test-key": "test-value-new", "updated_key": "updated_value"}`
var metaData meta.MetaData
err := json.Unmarshal([]byte(jsonData), &metaData)
assert.NoError(suite.T(), err)

update := coursePhaseDTO.UpdateCoursePhase{
ID: id,
Name: "Updated Phase",
IsInitialPhase: false,
MetaData: metaData,
}

err = UpdateCoursePhase(suite.ctx, update)
assert.NoError(suite.T(), err)

// Verify update
updatedCoursePhase, err := GetCoursePhaseByID(suite.ctx, id)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), "Updated Phase", updatedCoursePhase.Name, "Expected updated course phase name to match")
assert.False(suite.T(), updatedCoursePhase.IsInitialPhase, "Expected updated course phase to be an initial phase")
assert.Equal(suite.T(), meta.MetaData{"test-key": "test-value-new", "updated_key": "updated_value"}, updatedCoursePhase.MetaData, "Expected metadata to match updated data including the old data")
}

func (suite *CoursePhaseTestSuite) TestCreateCoursePhase() {
Expand Down

0 comments on commit 256c9ac

Please sign in to comment.