@@ -24,13 +24,44 @@ import (
2424
2525"github.com/arduino/go-paths-helper"
2626"github.com/stretchr/testify/require"
27+ "go.bug.st/f"
2728
2829"github.com/arduino/arduino-app-cli/internal/api/models"
30+ "github.com/arduino/arduino-app-cli/internal/e2e/client"
2931"github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
3032"github.com/arduino/arduino-app-cli/internal/orchestrator/config"
3133"github.com/arduino/arduino-app-cli/internal/store"
3234)
3335
36+ func setupTestBrick (t * testing.T ) (* client.CreateAppResp ,* client.ClientWithResponses ) {
37+ httpClient := GetHttpclient (t )
38+ createResp ,err := httpClient .CreateAppWithResponse (
39+ t .Context (),
40+ & client.CreateAppParams {SkipSketch :f .Ptr (true )},
41+ client.CreateAppRequest {
42+ Icon :f .Ptr ("💻" ),
43+ Name :"test-app" ,
44+ Description :f .Ptr ("My app description" ),
45+ },
46+ func (ctx context.Context ,req * http.Request )error {return nil },
47+ )
48+ require .NoError (t ,err )
49+ require .Equal (t ,http .StatusCreated ,createResp .StatusCode ())
50+ require .NotNil (t ,createResp .JSON201 )
51+
52+ resp ,err := httpClient .UpsertAppBrickInstanceWithResponse (
53+ t .Context (),
54+ * createResp .JSON201 .Id ,
55+ ImageClassifactionBrickID ,
56+ client.BrickCreateUpdateRequest {Model :f .Ptr ("mobilenet-image-classification" )},
57+ func (ctx context.Context ,req * http.Request )error {return nil },
58+ )
59+ require .NoError (t ,err )
60+ require .Equal (t ,http .StatusOK ,resp .StatusCode ())
61+
62+ return createResp ,httpClient
63+ }
64+
3465func TestBricksList (t * testing.T ) {
3566httpClient := GetHttpclient (t )
3667
@@ -56,8 +87,8 @@ func TestBricksList(t *testing.T) {
5687}
5788
5889func TestBricksDetails (t * testing.T ) {
90+ _ ,httpClient := setupTestBrick (t )
5991
60- httpClient := GetHttpclient (t )
6192t .Run ("should return 404 Not Found for an invalid brick ID" ,func (t * testing.T ) {
6293invalidBrickID := "notvalidBrickId"
6394var actualBody models.ErrorResponse
@@ -76,6 +107,14 @@ func TestBricksDetails(t *testing.T) {
76107t .Run ("should return 200 OK with full details for a valid brick ID" ,func (t * testing.T ) {
77108validBrickID := "arduino:image_classification"
78109
110+ expectedUsedByApps := []client.AppReference {
111+ {
112+ Id :f .Ptr ("dXNlcjp0ZXN0LWFwcA" ),
113+ Name :f .Ptr ("test-app" ),
114+ Icon :f .Ptr ("💻" ),
115+ },
116+ }
117+
79118response ,err := httpClient .GetBrickDetailsWithResponse (t .Context (),validBrickID ,func (ctx context.Context ,req * http.Request )error {return nil })
80119require .NoError (t ,err )
81120require .Equal (t ,http .StatusOK ,response .StatusCode (),"status code should be 200 ok" )
@@ -92,6 +131,7 @@ func TestBricksDetails(t *testing.T) {
92131require .Equal (t ,"path to the model file" ,* (* response .JSON200 .Variables )["EI_CLASSIFICATION_MODEL" ].Description )
93132require .Equal (t ,false ,* (* response .JSON200 .Variables )["EI_CLASSIFICATION_MODEL" ].Required )
94133require .NotEmpty (t ,* response .JSON200 .Readme )
95- require .Nil (t ,response .JSON200 .UsedByApps )
134+ require .NotNil (t ,response .JSON200 .UsedByApps ,"UsedByApps should not be nil" )
135+ require .Equal (t ,expectedUsedByApps ,* (response .JSON200 .UsedByApps ))
96136})
97137}