Skip to content

Commit

Permalink
fix: breaking failing tests (#22)
Browse files Browse the repository at this point in the history
* refactor: update MongoDB package references and 
* fix the failing tests
  • Loading branch information
Pradumnasaraf authored Nov 14, 2024
1 parent 1ac64c5 commit b943bbc
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions graph/schema.resolvers.go

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

2 changes: 1 addition & 1 deletion mongo/mongo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package database
package mongo

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/Pradumnasaraf/Contributors/graph"
"github.com/Pradumnasaraf/Contributors/handler"
"github.com/Pradumnasaraf/Contributors/middleware"
database "github.com/Pradumnasaraf/Contributors/mongo"
"github.com/Pradumnasaraf/Contributors/mongo"
"github.com/Pradumnasaraf/Contributors/prometheus"
"github.com/Pradumnasaraf/Contributors/redis"
"github.com/gin-gonic/gin"
Expand All @@ -20,7 +20,7 @@ func main() {

// Database connection
redis.RedisInit()
mongoClient := database.MongoInit()
mongoClient := mongo.MongoInit()
graph.GetMongoClient(mongoClient)
defer redis.RedisClose()

Expand Down
2 changes: 1 addition & 1 deletion tests/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ To update a contributor (e.g., U9), create the following document in your MongoD
To migrate all the data into the MongoDB, run the following command:

```bash
mongoimport --db opensource --collection contributors --file testdata.json --jsonArray --drop
mongoimport --db opensource --collection contributors --file tests/testdata.json --jsonArray --drop
```
12 changes: 12 additions & 0 deletions tests/addAContribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ import (
"net/http/httptest"
"testing"

"github.com/Pradumnasaraf/Contributors/config"
"github.com/Pradumnasaraf/Contributors/graph"
"github.com/Pradumnasaraf/Contributors/handler"
"github.com/Pradumnasaraf/Contributors/mongo"
"github.com/Pradumnasaraf/Contributors/redis"
"github.com/gin-gonic/gin"
"github.com/magiconair/properties/assert"
)

func TestAddAContribution(t *testing.T) {
// Config setup
config.Config()

// Database connection
redis.RedisInit()
mongoClient := mongo.MongoInit()
graph.GetMongoClient(mongoClient)
defer redis.RedisClose()

r := gin.Default()
r.POST("/graphql", handler.GraphqlHandler())
Expand Down
2 changes: 1 addition & 1 deletion tests/deleteAContributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDeleteAContributor(t *testing.T) {
return req
}(),
ExpectedStatus: http.StatusOK,
ExpectedBody: `{"errors":[{"message":"error while deleting the document. Document with the given ID may not exist","path":["deleteAContributor"]}],"data":null}`,
ExpectedBody: `{"errors":[{"message":"document not found. Document with the given ID may not exist","path":["deleteAContributor"]}],"data":null}`,
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/updateAContributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestUpdateAContributor(t *testing.T) {
return req
}(),
ExpectedStatus: http.StatusOK,
ExpectedBody: `{"errors":[{"message":"error while deleting the document. Document with the given ID may not exist","path":["deleteAContributor"]}],"data":null}`,
ExpectedBody: `{"errors":[{"message":"document not found. Document with the given ID may not exist","path":["deleteAContributor"]}],"data":null}`,
},
}

Expand Down

0 comments on commit b943bbc

Please sign in to comment.