Skip to content

Commit

Permalink
test(api) Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
aguszorza committed May 15, 2024
1 parent dbe48a0 commit d3f8d05
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/api-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
defaults:
run:
working-directory: ./
# if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'
if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'

steps:
- uses: actions/checkout@v4
Expand All @@ -102,7 +102,7 @@ jobs:
defaults:
run:
working-directory: ./
# if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'
if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cli-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
defaults:
run:
working-directory: ./
# if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'
if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'

steps:
- uses: actions/checkout@v4
Expand All @@ -99,7 +99,7 @@ jobs:
defaults:
run:
working-directory: ./
# if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'
if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'

steps:
- uses: actions/checkout@v4
Expand Down
31 changes: 16 additions & 15 deletions API/controllers/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
test_utils "p3/test/utils"
"p3/utils"
"slices"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -613,21 +614,21 @@ func TestGetLayersObjectsWithSimpleFilter(t *testing.T) {
assert.True(t, condition)
}

// func TestGetLayersObjectsWithDoubleFilter(t *testing.T) {
// endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer")
// expectedMessage := "successfully processed request"
// response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-*", nil, http.StatusOK, expectedMessage)
func TestGetLayersObjectsWithDoubleFilter(t *testing.T) {
endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer")
expectedMessage := "successfully processed request"
response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-*", nil, http.StatusOK, expectedMessage)

// data, exists := response["data"].([]any)
// assert.True(t, exists)
// assert.Equal(t, 2, len(data))
data, exists := response["data"].([]any)
assert.True(t, exists)
assert.Equal(t, 2, len(data))

// condition := true
// for _, rack := range data {
// condition = condition && strings.HasPrefix(rack.(map[string]any)["parentId"].(string), "site-no-temperature.building-1.room-")
// condition = condition && rack.(map[string]any)["category"] == "rack"
// condition = condition && rack.(map[string]any)["name"] == "rack-1"
// }
condition := true
for _, rack := range data {
condition = condition && strings.HasPrefix(rack.(map[string]any)["parentId"].(string), "site-no-temperature.building-1.room-")
condition = condition && rack.(map[string]any)["category"] == "rack"
condition = condition && rack.(map[string]any)["name"] == "rack-1"
}

// assert.True(t, condition)
// }
assert.True(t, condition)
}
46 changes: 23 additions & 23 deletions CLI/controllers/commandController_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,29 +777,29 @@ func TestIsEntityDrawableObjectNotFound(t *testing.T) {
assert.Equal(t, "object not found", err.Error())
}

// func TestIsEntityDrawable(t *testing.T) {
// tests := []struct {
// name string
// drawableObjects []int
// expectedIsDrawable bool
// }{
// {"CategoryIsNotDrawable", []int{models.EntityStrToInt("device")}, false},
// {"CategoryIsDrawable", []int{models.EntityStrToInt("rack")}, true},
// }

// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// controller, mockAPI, _ := layersSetup(t)
// controllers.State.DrawableObjs = tt.drawableObjects

// test_utils.MockGetObject(mockAPI, rack1)

// isDrawable, err := controller.IsEntityDrawable(models.PhysicalPath + "BASIC/A/R1/A01")
// assert.Equal(t, tt.expectedIsDrawable, isDrawable)
// assert.Nil(t, err)
// })
// }
// }
func TestIsEntityDrawable(t *testing.T) {
tests := []struct {
name string
drawableObjects []int
expectedIsDrawable bool
}{
{"CategoryIsNotDrawable", []int{models.EntityStrToInt("device")}, false},
{"CategoryIsDrawable", []int{models.EntityStrToInt("rack")}, true},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
controller, mockAPI, _ := layersSetup(t)
controllers.State.DrawableObjs = tt.drawableObjects

test_utils.MockGetObject(mockAPI, rack1)

isDrawable, err := controller.IsEntityDrawable(models.PhysicalPath + "BASIC/A/R1/A01")
assert.Equal(t, tt.expectedIsDrawable, isDrawable)
assert.Nil(t, err)
})
}
}

// Tests IsAttrDrawable (and IsCategoryAttrDrawable)
func TestIsAttrDrawableObjectNotFound(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ditrit_OGrEE-Core&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ditrit_OGrEE-Core)
[![API Coverage](https://raw.githubusercontent.com/ditrit/OGrEE-Core/coverage_badges/api_coverage_badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/api-unit-test.yml)
[![CLI Coverage](https://raw.githubusercontent.com/ditrit/OGrEE-Core/coverage_badges/cli_coverage_badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/cli-unit-test.yml)
[![CLI Coverage](https://raw.githubusercontent.com/ditrit/OGrEE-Core/cli_coverage_badge/cli_coverage_badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/cli-unit-test.yml)
[![⚙️ Build - Publish](https://github.com/ditrit/OGrEE-Core/actions/workflows/build-deploy.yaml/badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/build-deploy.yaml)

</div>
Expand Down

0 comments on commit d3f8d05

Please sign in to comment.