Skip to content

Commit

Permalink
unit tests complete successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
Roukoswarf committed Jan 5, 2024
1 parent 9c53b93 commit 0e326a1
Show file tree
Hide file tree
Showing 185 changed files with 9,410 additions and 4,138 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ service-restart-all:

test: ginkgo
@echo "ginkgo --require-suite --poll-progress-after=10s --poll-progress-interval=20s -r $(TEST)"
@cd $(ROOT_DIRECTORY) && . ./env.test.sh && ginkgo --require-suite --poll-progress-after=10s --poll-progress-interval=20s -r $(TEST)
@cd $(ROOT_DIRECTORY) && . ./env.test.sh && ginkgo --fail-fast --require-suite --poll-progress-after=10s --poll-progress-interval=20s -r $(TEST)

test-until-failure: ginkgo
@echo "ginkgo --require-suite --poll-progress-after=10s --poll-progress-interval=20s -r -untilItFails $(TEST)"
Expand Down
1 change: 1 addition & 0 deletions auth/test/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 23 additions & 12 deletions data/store/mongo/mongo_datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (d *DatumRepository) CreateDataSetData(ctx context.Context, dataSet *upload
now := time.Now().UTC()
timestamp := now.Truncate(time.Millisecond)

var insertData []mongo.WriteModel
insertData := make([]mongo.WriteModel, 0, len(dataSetData))

for _, datum := range dataSetData {
datum.SetUserID(dataSet.UserID)
Expand Down Expand Up @@ -613,26 +613,33 @@ func (d *DatumRepository) GetDataRange(ctx context.Context, userId string, typ s
// return nil, fmt.Errorf("provided dataRecords type %T cannot be decoded into", v)
//}

startTime := status.FirstData
endTime := status.LastData
// quit early if range is 0
if status.FirstData.Equal(status.LastData) {
return nil, nil
}

// return error if ranges are inverted, as this can produce unexpected results
if status.FirstData.After(status.LastData) {
return nil, fmt.Errorf("FirstData (%s) after LastData (%s) for user %s", status.FirstData, status.LastData, userId)
}

// quit early if range is 0
if startTime.Equal(endTime) {
if status.LastUpdated.Equal(status.LastData) {
return nil, nil
}

// return error if ranges are inverted, as this can produce unexpected results
if startTime.After(endTime) {
return nil, fmt.Errorf("startTime (%s) after endTime (%s) for user %s", startTime, endTime, userId)
if status.LastUpdated.After(status.NextLastUpdated) {
return nil, fmt.Errorf("LastUpdated (%s) after NextLastUpdated (%s) for user %s", status.LastUpdated, status.NextLastUpdated, userId)
}

selector := bson.M{
"_active": true,
"_userId": userId,
"type": typ,
"time": bson.M{
"$gt": startTime,
"$lte": endTime,
"$gt": status.FirstData,
"$lte": status.LastData,
},
"modifiedTime": bson.M{
"$gt": status.LastUpdated,
Expand All @@ -659,6 +666,10 @@ func (d *DatumRepository) GetLastUpdatedForUser(ctx context.Context, userId stri
return errors.New("context is missing")
}

if status == nil {
return errors.New("status is missing")
}

if userId == "" {
return errors.New("userId is empty")
}
Expand Down Expand Up @@ -702,7 +713,7 @@ func (d *DatumRepository) GetLastUpdatedForUser(ctx context.Context, userId stri
return fmt.Errorf("unable to decode last %s time: %w", typ, err)
}

// if we have no record
// if we have a record
if len(dataSet) > 0 {
status.LastData = dataSet[0].Time.UTC()
status.FirstData = status.LastData.AddDate(0, 0, -types.HoursAgoToKeep/24)
Expand All @@ -728,7 +739,7 @@ func (d *DatumRepository) GetLastUpdatedForUser(ctx context.Context, userId stri
return fmt.Errorf("unable to decode last %s modifiedTime: %w", typ, err)
}

// if we have no record
// if we have a record
if len(dataSet) > 0 {
status.LastUpload = dataSet[0].ModifiedTime.UTC()
}
Expand All @@ -755,9 +766,9 @@ func (d *DatumRepository) GetLastUpdatedForUser(ctx context.Context, userId stri
return fmt.Errorf("unable to decode earliest %s recently modified time: %w", typ, err)
}

// if we have no record
// if we have a record
if len(dataSet) > 0 {
status.LastUpload = dataSet[0].ModifiedTime.UTC()
status.EarliestModified = dataSet[0].Time.UTC()
}

return nil
Expand Down
Loading

0 comments on commit 0e326a1

Please # to comment.