Skip to content

Commit ca459b5

Browse files
mirkoCrobumirkoCrobu
andauthored
Create default template file to create app (#651)
Co-authored-by: mirkoCrobu <mirkocrobu@NB-0531.localdomain>
1 parent cdb6b44 commit ca459b5

File tree

16 files changed

+646
-90
lines changed

16 files changed

+646
-90
lines changed

cmd/arduino-app-cli/app/new.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414

1515
func newCreateCmd(cfg config.Configuration) *cobra.Command {
1616
var (
17-
icon string
18-
bricks []string
19-
noPyton bool
20-
noSketch bool
21-
fromApp string
17+
icon string
18+
description string
19+
bricks []string
20+
noPyton bool
21+
noSketch bool
22+
fromApp string
2223
)
2324

2425
cmd := &cobra.Command{
@@ -28,11 +29,12 @@ func newCreateCmd(cfg config.Configuration) *cobra.Command {
2829
RunE: func(cmd *cobra.Command, args []string) error {
2930
cobra.MinimumNArgs(1)
3031
name := args[0]
31-
return createHandler(cmd.Context(), cfg, name, icon, noPyton, noSketch, fromApp)
32+
return createHandler(cmd.Context(), cfg, name, icon, description, noPyton, noSketch, fromApp)
3233
},
3334
}
3435

3536
cmd.Flags().StringVarP(&icon, "icon", "i", "", "Icon for the app")
37+
cmd.Flags().StringVarP(&description, "description", "d", "", "Description for the app")
3638
cmd.Flags().StringVarP(&fromApp, "from-app", "", "", "Create the new app from the path of an existing app")
3739
cmd.Flags().StringArrayVarP(&bricks, "bricks", "b", []string{}, "List of bricks to include in the app")
3840
cmd.Flags().BoolVarP(&noPyton, "no-python", "", false, "Do not include Python files")
@@ -42,7 +44,7 @@ func newCreateCmd(cfg config.Configuration) *cobra.Command {
4244
return cmd
4345
}
4446

45-
func createHandler(ctx context.Context, cfg config.Configuration, name string, icon string, noPython, noSketch bool, fromApp string) error {
47+
func createHandler(ctx context.Context, cfg config.Configuration, name string, icon string, description string, noPython, noSketch bool, fromApp string) error {
4648
if fromApp != "" {
4749
id, err := servicelocator.GetAppIDProvider().ParseID(fromApp)
4850
if err != nil {
@@ -68,10 +70,11 @@ func createHandler(ctx context.Context, cfg config.Configuration, name string, i
6870

6971
} else {
7072
resp, err := orchestrator.CreateApp(ctx, orchestrator.CreateAppRequest{
71-
Name: name,
72-
Icon: icon,
73-
SkipPython: noPython,
74-
SkipSketch: noSketch,
73+
Name: name,
74+
Icon: icon,
75+
Description: description,
76+
SkipPython: noPython,
77+
SkipSketch: noSketch,
7578
}, servicelocator.GetAppIDProvider(), cfg)
7679
if err != nil {
7780
feedback.Fatal(err.Error(), feedback.ErrGeneric)

internal/api/docs/openapi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,9 @@ components:
11041104
type: object
11051105
CreateAppRequest:
11061106
properties:
1107+
description:
1108+
description: application description
1109+
type: string
11071110
icon:
11081111
description: application icon
11091112
type: string

internal/api/handlers/app_create.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import (
1515
)
1616

1717
type CreateAppRequest struct {
18-
Name string `json:"name" description:"application name" example:"My Awesome App" required:"true"`
19-
Icon string `json:"icon" description:"application icon" `
18+
Name string `json:"name" description:"application name" example:"My Awesome App" required:"true"`
19+
Icon string `json:"icon" description:"application icon" `
20+
Description string `json:"description" description:"application description" `
2021
}
2122

2223
func HandleAppCreate(
@@ -49,10 +50,11 @@ func HandleAppCreate(
4950
resp, err := orchestrator.CreateApp(
5051
r.Context(),
5152
orchestrator.CreateAppRequest{
52-
Name: req.Name,
53-
Icon: req.Icon,
54-
SkipPython: skipPython,
55-
SkipSketch: skipSketch,
53+
Name: req.Name,
54+
Icon: req.Icon,
55+
Description: req.Description,
56+
SkipPython: skipPython,
57+
SkipSketch: skipSketch,
5658
},
5759
idProvider,
5860
cfg,

internal/e2e/client/client.gen.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/e2e/daemon/app_test.go

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func TestCreateApp(t *testing.T) {
1919
httpClient := GetHttpclient(t)
2020

2121
defaultRequestBody := client.CreateAppRequest{
22-
Icon: f.Ptr("🌎"),
23-
Name: "HelloWorld",
22+
Icon: f.Ptr("🌎"),
23+
Name: "HelloWorld",
24+
Description: f.Ptr("My HelloWorld description"),
2425
}
2526

2627
testCases := []struct {
@@ -56,8 +57,9 @@ func TestCreateApp(t *testing.T) {
5657
SkipSketch: f.Ptr(false),
5758
},
5859
body: client.CreateAppRequest{
59-
Icon: f.Ptr("🌎"),
60-
Name: "HelloWorld_2",
60+
Icon: f.Ptr("🌎"),
61+
Name: "HelloWorld_2",
62+
Description: f.Ptr("My HelloWorld_2 description"),
6163
},
6264
expectedStatusCode: http.StatusCreated,
6365
},
@@ -68,8 +70,9 @@ func TestCreateApp(t *testing.T) {
6870
SkipSketch: f.Ptr(true),
6971
},
7072
body: client.CreateAppRequest{
71-
Icon: f.Ptr("🌎"),
72-
Name: "HelloWorld_3",
73+
Icon: f.Ptr("🌎"),
74+
Name: "HelloWorld_3",
75+
Description: f.Ptr("My HelloWorld_3 description"),
7376
},
7477
expectedStatusCode: http.StatusCreated,
7578
},
@@ -107,6 +110,47 @@ func TestCreateApp(t *testing.T) {
107110
}
108111
}
109112

113+
func TestCreateAndVerifyAppDetails(t *testing.T) {
114+
httpClient := GetHttpclient(t)
115+
appToCreate := client.CreateAppRequest{
116+
Icon: f.Ptr("🧪"),
117+
Name: "test-app-for-verification",
118+
Description: f.Ptr("A description for the verification test."),
119+
}
120+
121+
createResp, err := httpClient.CreateAppWithResponse(
122+
t.Context(),
123+
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
124+
appToCreate,
125+
)
126+
127+
require.NoError(t, err)
128+
require.Equal(t, http.StatusCreated, createResp.StatusCode())
129+
require.NotNil(t, createResp.JSON201, "The creation response body should not be nil")
130+
require.NotNil(t, createResp.JSON201.Id, "The created app ID should not be nil")
131+
132+
createdAppId := *createResp.JSON201.Id
133+
134+
detailsResp, err := httpClient.GetAppDetailsWithResponse(t.Context(), createdAppId)
135+
136+
require.NoError(t, err)
137+
require.Equal(t, http.StatusOK, detailsResp.StatusCode())
138+
require.NotNil(t, detailsResp.JSON200, "The get details response body should not be nil")
139+
140+
retrievedApp := detailsResp.JSON200
141+
142+
require.Equal(t, createdAppId, retrievedApp.Id)
143+
require.Equal(t, appToCreate.Name, retrievedApp.Name)
144+
require.Equal(t, *appToCreate.Icon, *retrievedApp.Icon)
145+
require.Equal(t, *appToCreate.Description, *retrievedApp.Description)
146+
147+
require.False(t, *retrievedApp.Example, "A new app should not be an 'example'")
148+
require.False(t, *retrievedApp.Default, "A new app should not be 'default'")
149+
require.Equal(t, client.Stopped, retrievedApp.Status, "The initial status of a new app should be 'stopped'")
150+
require.Empty(t, retrievedApp.Bricks, "A new app should not have 'bricks'")
151+
require.NotEmpty(t, retrievedApp.Path, "The app path should not be empty")
152+
}
153+
110154
func TestEditApp(t *testing.T) {
111155
httpClient := GetHttpclient(t)
112156

@@ -115,8 +159,9 @@ func TestEditApp(t *testing.T) {
115159
t.Context(),
116160
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
117161
client.CreateAppRequest{
118-
Icon: f.Ptr("💻"),
119-
Name: appName,
162+
Icon: f.Ptr("💻"),
163+
Name: appName,
164+
Description: f.Ptr("My app description"),
120165
},
121166
)
122167
require.NoError(t, err)
@@ -192,8 +237,9 @@ func TestEditApp(t *testing.T) {
192237
t.Context(),
193238
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
194239
client.CreateAppRequest{
195-
Icon: f.Ptr("💻"),
196-
Name: "new-valid-app",
240+
Icon: f.Ptr("💻"),
241+
Name: "new-valid-app",
242+
Description: f.Ptr("My app description"),
197243
},
198244
)
199245
require.NoError(t, err)
@@ -230,8 +276,9 @@ func TestDeleteApp(t *testing.T) {
230276
t.Context(),
231277
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
232278
client.CreateAppRequest{
233-
Icon: f.Ptr("🗑️"),
234-
Name: appToDeleteName,
279+
Icon: f.Ptr("🗑️"),
280+
Name: appToDeleteName,
281+
Description: f.Ptr("My app description"),
235282
},
236283
)
237284
require.NoError(t, err)
@@ -375,8 +422,9 @@ func TestAppClone(t *testing.T) {
375422
t.Context(),
376423
&client.CreateAppParams{},
377424
client.CreateAppRequest{
378-
Icon: f.Ptr("📄"),
379-
Name: "source-app",
425+
Icon: f.Ptr("📄"),
426+
Name: "source-app",
427+
Description: f.Ptr("My app description"),
380428
},
381429
)
382430
require.NoError(t, err)
@@ -387,8 +435,9 @@ func TestAppClone(t *testing.T) {
387435
t.Context(),
388436
&client.CreateAppParams{},
389437
client.CreateAppRequest{
390-
Icon: f.Ptr("🚫"),
391-
Name: "existing-clone-name",
438+
Icon: f.Ptr("🚫"),
439+
Name: "existing-clone-name",
440+
Description: f.Ptr("My app description"),
392441
},
393442
)
394443
require.NoError(t, err)
@@ -492,8 +541,9 @@ func TestAppLogs(t *testing.T) {
492541
t.Context(),
493542
&client.CreateAppParams{},
494543
client.CreateAppRequest{
495-
Icon: f.Ptr("📜"),
496-
Name: "app-with-logs",
544+
Icon: f.Ptr("📜"),
545+
Name: "app-with-logs",
546+
Description: f.Ptr("My app description"),
497547
},
498548
)
499549
require.NoError(t, err)
@@ -556,8 +606,9 @@ func TestAppDetails(t *testing.T) {
556606
t.Context(),
557607
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
558608
client.CreateAppRequest{
559-
Icon: f.Ptr("💻"),
560-
Name: appName,
609+
Icon: f.Ptr("💻"),
610+
Name: appName,
611+
Description: f.Ptr("My app description"),
561612
},
562613
)
563614
require.NoError(t, err)
@@ -582,6 +633,7 @@ func TestAppDetails(t *testing.T) {
582633
require.Equal(t, *appID, detailsResp.JSON200.Id)
583634
require.Equal(t, appName, detailsResp.JSON200.Name)
584635
require.Equal(t, "💻", *detailsResp.JSON200.Icon)
636+
require.Equal(t, "My app description", *detailsResp.JSON200.Description)
585637
require.Len(t, *detailsResp.JSON200.Bricks, 1)
586638
require.Equal(t,
587639
client.AppDetailedBrick{
@@ -607,8 +659,9 @@ func TestAppPorts(t *testing.T) {
607659
t.Context(),
608660
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
609661
client.CreateAppRequest{
610-
Icon: f.Ptr("💻"),
611-
Name: "test-app",
662+
Icon: f.Ptr("💻"),
663+
Name: "test-app",
664+
Description: f.Ptr("My app description"),
612665
},
613666
func(ctx context.Context, req *http.Request) error { return nil },
614667
)
@@ -652,8 +705,9 @@ func TestAppPorts(t *testing.T) {
652705
t.Context(),
653706
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
654707
client.CreateAppRequest{
655-
Icon: f.Ptr("💻"),
656-
Name: "test-app-2",
708+
Icon: f.Ptr("💻"),
709+
Name: "test-app-2",
710+
Description: f.Ptr("My app description"),
657711
},
658712
func(ctx context.Context, req *http.Request) error { return nil },
659713
)

internal/e2e/daemon/instance_bricks_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ func setupTestApp(t *testing.T) (*client.CreateAppResp, *client.ClientWithRespon
2222
t.Context(),
2323
&client.CreateAppParams{SkipSketch: f.Ptr(true)},
2424
client.CreateAppRequest{
25-
Icon: f.Ptr("💻"),
26-
Name: "test-app",
25+
Icon: f.Ptr("💻"),
26+
Name: "test-app",
27+
Description: f.Ptr("My app description"),
2728
},
2829
func(ctx context.Context, req *http.Request) error { return nil },
2930
)

0 commit comments

Comments
 (0)