Skip to content

Commit

Permalink
Merge pull request stakwork#2508 from stakwork/feat/unit_tests_coverage
Browse files Browse the repository at this point in the history
Feat: added test coverage report and fix failing tests
  • Loading branch information
elraphty authored Jan 29, 2025
2 parents bedb818 + d47d834 commit 578acab
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ jobs:
- name: Install cover
run: go get golang.org/x/tools/cmd/cover

- name: Tests
run: sudo V2_BOT_URL=http://localhost:3005 V2_BOT_TOKEN=xyzxyzxyz go test ./... -race -v -coverprofile=coverage.out && ./cover-check.sh coverage.out 8.4
- name: Run Tests with Race Detector and Generate Coverage (Excluding Mocks)
run: |
PKGS=$(sudo go list ./... | grep -v '/mocks' | tr '\n' ',')
TEST_PKGS=$(sudo go list ./... | grep -v '/mocks')
sudo V2_BOT_URL=http://localhost:3005 V2_BOT_TOKEN=xyzxyzxyz go test -race -coverprofile=coverage.out -coverpkg=$PKGS $TEST_PKGS
- name: Show Coverage Summary
run: |
sudo go tool cover -func=coverage.out
- name: Droping DB with docker compose
run: docker compose -f ./docker/testdb-docker-compose.yml -p test_db down
Expand Down
35 changes: 18 additions & 17 deletions db/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func InitTestDB() {
logger.Log.Info("DB CONNECTED")

db.Exec(`
DO $$ BEGIN
ALTER TABLE tickets
ALTER COLUMN feature_uuid DROP NOT NULL,
ALTER COLUMN phase_uuid DROP NOT NULL;
EXCEPTION
WHEN others THEN null;
END $$;
`)
DO $$ BEGIN
ALTER TABLE tickets
ALTER COLUMN feature_uuid DROP NOT NULL,
ALTER COLUMN phase_uuid DROP NOT NULL;
EXCEPTION
WHEN others THEN null;
END $$;
`)

// migrate table changes
db.AutoMigrate(&Tribe{})
Expand Down Expand Up @@ -79,8 +79,8 @@ func InitTestDB() {
db.AutoMigrate(&Bounty{})
db.AutoMigrate(&Notification{})
db.AutoMigrate(&BountyTiming{})
db.AutoMigrate(&TextSnippet{})
db.AutoMigrate(&FileAsset{})
db.AutoMigrate(&TextSnippet{})

people := TestDB.GetAllPeople()
for _, p := range people {
Expand All @@ -98,9 +98,16 @@ func DeleteAllChats() {
TestDB.db.Exec("DELETE FROM chats")
}

func CleanTestData() {
func DeleteAllBounties() {
TestDB.db.Exec("DELETE FROM bounty")
}

func DeleteAllFeatureStories() {
TestDB.db.Exec("DELETE FROM feature_stories")
}

TestDB.DeleteAllBounties()
func CleanTestData() {
TestDB.db.Exec("DELETE FROM bounty")

TestDB.db.Exec("DELETE FROM workspaces")

Expand All @@ -115,12 +122,6 @@ func CleanTestData() {
TestDB.db.Exec("DELETE FROM chats")

TestDB.db.Exec("DELETE FROM notifications")

TestDB.db.Exec("DELETE FROM feature_stories")

TestDB.db.Exec("DELETE FROM text_snippets")

TestDB.db.Exec("DELETE FROM file_assets")
}

func DeleteAllChatMessages() {
Expand Down
19 changes: 9 additions & 10 deletions handlers/bounties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,17 @@ func createValidBounty() map[string]interface{} {
}

func TestGetWantedsHeader(t *testing.T) {

db.InitTestDB()

db.CleanTestData()

defer func() {
db.CleanTestData()
db.CloseTestDB()
}()

originalDB := db.DB
defer func() {
db.DB = originalDB
}()

db.DB = db.TestDB

db.CleanTestData()

tests := []struct {
name string
setupTestData func(t *testing.T)
Expand Down Expand Up @@ -434,8 +429,10 @@ func TestGetWantedsHeader(t *testing.T) {
},
},
{
name: "No Developers",
setupTestData: func(t *testing.T) {},
name: "No Developers",
setupTestData: func(t *testing.T) {
db.DeleteAllBounties()
},
expectedStatus: http.StatusOK,
validate: func(t *testing.T, response []byte) {
var result struct {
Expand Down Expand Up @@ -603,6 +600,8 @@ func TestGetWantedsHeader(t *testing.T) {
}
_, err := db.TestDB.CreateOrEditPerson(person)
assert.NoError(t, err)

db.DeleteAllBounties()
},
expectedStatus: http.StatusOK,
validate: func(t *testing.T, response []byte) {
Expand Down
12 changes: 10 additions & 2 deletions handlers/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3691,8 +3691,8 @@ func TestGetFeatureStories(t *testing.T) {
})

t.Run("Should not add user stories if stories array is empty", func(t *testing.T) {
db.DeleteAllFeatureStories()

db.CleanTestData()
db.TestDB.CreateOrEditPerson(person)
db.TestDB.CreateOrEditWorkspace(workspace)
db.TestDB.CreateOrEditFeature(feature)
Expand Down Expand Up @@ -3897,10 +3897,18 @@ func TestGetFeatureStories(t *testing.T) {
})

t.Run("Duplicate Stories", func(t *testing.T) {

db.CleanTestData()
db.TestDB.CreateOrEditPerson(person)
db.TestDB.CreateOrEditWorkspace(workspace)

feature := db.WorkspaceFeatures{
Uuid: uuid.New().String(),
WorkspaceUuid: workspace.Uuid,
Name: "test-get-feature-stories-duplicate-content",
Url: "https://github.com/test-get-feature-stories-feature-url",
Priority: 0,
}

db.TestDB.CreateOrEditFeature(feature)

duplicateStory := db.FeatureStories{
Expand Down

0 comments on commit 578acab

Please sign in to comment.