From a1433effdb3d8e3d6e92c0c64a23aa707c41e9af Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Wed, 9 Oct 2024 17:12:42 +0200 Subject: [PATCH 1/4] add story test --- ...ttachedPropertyValuesAlwaysInclude_test.go | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go diff --git a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go new file mode 100644 index 000000000..4c74b74be --- /dev/null +++ b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go @@ -0,0 +1,63 @@ +package stories + +import ( + "context" + pb "gen/services/property_svc/v1" + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "hwtesting" + "testing" +) + +func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { + ctx := context.Background() + propertyClient := propertyServiceClient() + propertyValueClient := propertyValueServiceClient() + propertyViewClient := propertyViewServiceClient() + + patientID := uuid.New().String() + + // Create a property + property, err := propertyClient.CreateProperty(ctx, &pb.CreatePropertyRequest{ + SubjectType: pb.SubjectType_SUBJECT_TYPE_PATIENT, + FieldType: pb.FieldType_FIELD_TYPE_NUMBER, + Name: t.Name(), + Description: nil, + }) + assert.NoError(t, err) + hwtesting.WaitForProjectionsToSettle() + + // Don't create a property value + + // Add property to the always_include list of an arbitrary subject + _, err = propertyViewClient.UpdatePropertyViewRule(ctx, &pb.UpdatePropertyViewRuleRequest{ + FilterUpdate: &pb.FilterUpdate{ + AppendToAlwaysInclude: []string{property.PropertyId}, + }, + Matcher: &pb.UpdatePropertyViewRuleRequest_PatientMatcher{ + PatientMatcher: &pb.PatientPropertyMatcher{ + WardId: nil, + PatientId: &patientID, + }, + }, + }) + assert.NoError(t, err) + hwtesting.WaitForProjectionsToSettle() + + // Call GetAttachedPropertyValues for this arbitrary patient or task + + res, err := propertyValueClient.GetAttachedPropertyValues(ctx, &pb.GetAttachedPropertyValuesRequest{ + Matcher: &pb.GetAttachedPropertyValuesRequest_PatientMatcher{ + PatientMatcher: &pb.PatientPropertyMatcher{ + WardId: nil, + PatientId: &patientID, + }, + }, + }) + assert.NoError(t, err) + + // Property shows up + assert.Len(t, res.Values, 1) + assert.Equal(t, res.Values[0].PropertyId, property.PropertyId) + +} From c1a53059946d6ef9c5b74235de5fc88a960c7b57 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 22 Oct 2024 15:17:41 +0200 Subject: [PATCH 2/4] still works --- ...ttachedPropertyValuesAlwaysInclude_test.go | 111 +++++++++++------- 1 file changed, 66 insertions(+), 45 deletions(-) diff --git a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go index 4c74b74be..79da5faac 100644 --- a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go +++ b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go @@ -9,55 +9,76 @@ import ( "testing" ) -func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { +func TestGetAttachedPropertyValuesAlwaysIncludeBasicValues(t *testing.T) { ctx := context.Background() propertyClient := propertyServiceClient() propertyValueClient := propertyValueServiceClient() propertyViewClient := propertyViewServiceClient() - patientID := uuid.New().String() - - // Create a property - property, err := propertyClient.CreateProperty(ctx, &pb.CreatePropertyRequest{ - SubjectType: pb.SubjectType_SUBJECT_TYPE_PATIENT, - FieldType: pb.FieldType_FIELD_TYPE_NUMBER, - Name: t.Name(), - Description: nil, - }) - assert.NoError(t, err) - hwtesting.WaitForProjectionsToSettle() - - // Don't create a property value - - // Add property to the always_include list of an arbitrary subject - _, err = propertyViewClient.UpdatePropertyViewRule(ctx, &pb.UpdatePropertyViewRuleRequest{ - FilterUpdate: &pb.FilterUpdate{ - AppendToAlwaysInclude: []string{property.PropertyId}, - }, - Matcher: &pb.UpdatePropertyViewRuleRequest_PatientMatcher{ - PatientMatcher: &pb.PatientPropertyMatcher{ - WardId: nil, - PatientId: &patientID, - }, - }, - }) - assert.NoError(t, err) - hwtesting.WaitForProjectionsToSettle() - - // Call GetAttachedPropertyValues for this arbitrary patient or task - - res, err := propertyValueClient.GetAttachedPropertyValues(ctx, &pb.GetAttachedPropertyValuesRequest{ - Matcher: &pb.GetAttachedPropertyValuesRequest_PatientMatcher{ - PatientMatcher: &pb.PatientPropertyMatcher{ - WardId: nil, - PatientId: &patientID, - }, - }, - }) - assert.NoError(t, err) - - // Property shows up - assert.Len(t, res.Values, 1) - assert.Equal(t, res.Values[0].PropertyId, property.PropertyId) + subjectTypes := []pb.SubjectType{ + pb.SubjectType_SUBJECT_TYPE_PATIENT, + pb.SubjectType_SUBJECT_TYPE_TASK, + } + + fieldTypes := []pb.FieldType{ + pb.FieldType_FIELD_TYPE_TEXT, + pb.FieldType_FIELD_TYPE_NUMBER, + pb.FieldType_FIELD_TYPE_CHECKBOX, + pb.FieldType_FIELD_TYPE_DATE, + pb.FieldType_FIELD_TYPE_DATE_TIME, + pb.FieldType_FIELD_TYPE_SELECT, + pb.FieldType_FIELD_TYPE_MULTI_SELECT, + } + + for _, subjectType := range subjectTypes { + for _, fieldType := range fieldTypes { + t.Run(t.Name()+"_"+subjectType.String()+"_"+fieldType.String(), func(t *testing.T) { + subjectID := uuid.New().String() + + // Create a property + property, err := propertyClient.CreateProperty(ctx, &pb.CreatePropertyRequest{ + SubjectType: subjectType, + FieldType: fieldType, + Name: t.Name(), + Description: nil, + }) + assert.NoError(t, err) + hwtesting.WaitForProjectionsToSettle() + + // Don't create a property value + + // Add property to the always_include list of an arbitrary subject + _, err = propertyViewClient.UpdatePropertyViewRule(ctx, &pb.UpdatePropertyViewRuleRequest{ + FilterUpdate: &pb.FilterUpdate{ + AppendToAlwaysInclude: []string{property.PropertyId}, + }, + Matcher: &pb.UpdatePropertyViewRuleRequest_PatientMatcher{ + PatientMatcher: &pb.PatientPropertyMatcher{ + WardId: nil, + PatientId: &subjectID, + }, + }, + }) + assert.NoError(t, err) + hwtesting.WaitForProjectionsToSettle() + + // Call GetAttachedPropertyValues for this arbitrary patient or task + + res, err := propertyValueClient.GetAttachedPropertyValues(ctx, &pb.GetAttachedPropertyValuesRequest{ + Matcher: &pb.GetAttachedPropertyValuesRequest_PatientMatcher{ + PatientMatcher: &pb.PatientPropertyMatcher{ + WardId: nil, + PatientId: &subjectID, + }, + }, + }) + assert.NoError(t, err) + + // Property shows up + assert.Len(t, res.Values, 1) + assert.Equal(t, res.Values[0].PropertyId, property.PropertyId) + }) + } + } } From 6e502a90e38b8dc68cda56d2f360420750a5f011 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 22 Oct 2024 15:19:20 +0200 Subject: [PATCH 3/4] rename back --- .../stories/GetAttachedPropertyValuesAlwaysInclude_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go index 79da5faac..306c98da5 100644 --- a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go +++ b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -func TestGetAttachedPropertyValuesAlwaysIncludeBasicValues(t *testing.T) { +func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { ctx := context.Background() propertyClient := propertyServiceClient() propertyValueClient := propertyValueServiceClient() From 7297c0e22fe53f9bfa075a8336f69601ca1ce51b Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 22 Oct 2024 15:20:48 +0200 Subject: [PATCH 4/4] fi xlinter issues --- ...GetAttachedPropertyValuesAlwaysInclude_test.go | 15 ++++++++------- .../patient/commands/v1/discharge_patient.go | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go index 306c98da5..4b63727d1 100644 --- a/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go +++ b/services/property-svc/stories/GetAttachedPropertyValuesAlwaysInclude_test.go @@ -3,10 +3,12 @@ package stories import ( "context" pb "gen/services/property_svc/v1" - "github.com/google/uuid" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "hwtesting" "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/assert" ) func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { @@ -42,7 +44,7 @@ func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { Name: t.Name(), Description: nil, }) - assert.NoError(t, err) + require.NoError(t, err) hwtesting.WaitForProjectionsToSettle() // Don't create a property value @@ -59,7 +61,7 @@ func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { }, }, }) - assert.NoError(t, err) + require.NoError(t, err) hwtesting.WaitForProjectionsToSettle() // Call GetAttachedPropertyValues for this arbitrary patient or task @@ -72,13 +74,12 @@ func TestGetAttachedPropertyValuesAlwaysInclude(t *testing.T) { }, }, }) - assert.NoError(t, err) + require.NoError(t, err) // Property shows up - assert.Len(t, res.Values, 1) + require.Len(t, res.Values, 1) assert.Equal(t, res.Values[0].PropertyId, property.PropertyId) }) } } - } diff --git a/services/tasks-svc/internal/patient/commands/v1/discharge_patient.go b/services/tasks-svc/internal/patient/commands/v1/discharge_patient.go index 2a054b30f..99466915a 100644 --- a/services/tasks-svc/internal/patient/commands/v1/discharge_patient.go +++ b/services/tasks-svc/internal/patient/commands/v1/discharge_patient.go @@ -23,7 +23,7 @@ func NewDischargePatientCommandHandler(as hwes.AggregateStore) DischargePatientC return 0, err } - // If a patient is beeing discharged, the patient is also being unassigned from the bed + // If a patient is being discharged, the patient is also being unassigned from the bed if err := a.UnassignBed(ctx); err != nil { return 0, err }