@@ -20,7 +20,6 @@ const createExportStub = (opts) => ({
20
20
} ,
21
21
created_at : "2025-01-02T22:59:51" ,
22
22
updated_at : "2025-01-02T22:59:51" ,
23
- destination_uri : "" ,
24
23
...opts ,
25
24
} ) ;
26
25
@@ -34,113 +33,109 @@ describe("export create s3", () => {
34
33
( { createExport } = container . resolve ( "accountAPI" ) ) ;
35
34
} ) ;
36
35
37
- it ( "creates an export" , async ( ) => {
38
- const database = "us-std/example" ;
39
- const bucket = "test-bucket" ;
40
- const path = "/test/key" ;
41
- const stubbedResponse = createExportStub ( {
42
- database,
43
- destination : {
44
- s3 : {
45
- path,
46
- bucket,
47
- } ,
48
- } ,
49
- format : "simple" ,
50
- } ) ;
51
- createExport . resolves ( stubbedResponse ) ;
52
-
53
- await run (
54
- `export create s3 --database '${ database } ' --bucket '${ bucket } ' --path '${ path } '` ,
55
- container ,
56
- ) ;
57
- await stdout . waitForWritten ( ) ;
36
+ const scenarios = [
37
+ {
38
+ description : "using --destination" ,
39
+ args : "--destination 's3://test-bucket/test/key'" ,
40
+ expectedDestination : "s3://test-bucket/test/key" ,
41
+ expectedDestArgs : "s3://test-bucket/test/key" ,
42
+ } ,
43
+ {
44
+ description : "using --bucket and --path" ,
45
+ args : "--bucket 'test-bucket' --path '/test/key'" ,
46
+ expectedDestination : "s3://test-bucket/test/key" ,
47
+ expectedDestArgs : { s3 : { bucket : "test-bucket" , path : "/test/key" } } ,
48
+ } ,
49
+ ] ;
50
+
51
+ scenarios . forEach (
52
+ ( { description, args, expectedDestination, expectedDestArgs } ) => {
53
+ it ( `creates an export ${ description } ` , async ( ) => {
54
+ const database = "us-std/example" ;
55
+ const stubbedResponse = createExportStub ( {
56
+ database,
57
+ destination : expectedDestination ,
58
+ format : "simple" ,
59
+ } ) ;
60
+ createExport . resolves ( stubbedResponse ) ;
61
+
62
+ await run (
63
+ `export create s3 --database '${ database } ' ${ args } ` ,
64
+ container ,
65
+ ) ;
66
+ await stdout . waitForWritten ( ) ;
58
67
59
- expect ( stdout . getWritten ( ) ) . to . equal ( `id: test-export-id
68
+ expect ( stdout . getWritten ( ) ) . to . equal ( `id: test-export-id
60
69
state: Pending
61
70
database: us-std/example
62
71
format: simple
63
- destination:
64
- s3:
65
- path: /test/key
66
- bucket: test-bucket
72
+ destination: s3://test-bucket/test/key
67
73
created_at: 2025-01-02T22:59:51
68
74
updated_at: 2025-01-02T22:59:51
69
- destination_uri: ""
70
75
` ) ;
71
- expect ( createExport ) . to . have . been . calledWith ( {
72
- database,
73
- collections : [ ] ,
74
- destination : {
75
- s3 : {
76
- bucket,
77
- path,
78
- } ,
79
- } ,
80
- format : "simple" ,
81
- } ) ;
82
- } ) ;
76
+ expect ( createExport ) . to . have . been . calledWith ( {
77
+ database,
78
+ collections : [ ] ,
79
+ destination : expectedDestArgs ,
80
+ format : "simple" ,
81
+ } ) ;
82
+ } ) ;
83
83
84
- it ( "outputs the full response with --json" , async ( ) => {
85
- const database = "us-std/example" ;
86
- const bucket = "test-bucket" ;
87
- const path = "/test/key" ;
88
- const stubbedResponse = createExportStub ( {
89
- database,
90
- destination : {
91
- s3 : {
92
- path,
93
- bucket,
94
- } ,
95
- } ,
96
- format : "simple" ,
97
- } ) ;
98
- createExport . resolves ( stubbedResponse ) ;
99
-
100
- await run (
101
- `export create s3 --database '${ database } ' --bucket '${ bucket } ' --path '${ path } ' --json` ,
102
- container ,
103
- ) ;
104
- await stdout . waitForWritten ( ) ;
84
+ it ( `outputs the full response with --json ${ description } ` , async ( ) => {
85
+ const database = "us-std/example" ;
86
+ const stubbedResponse = createExportStub ( {
87
+ database,
88
+ destination : expectedDestination ,
89
+ format : "simple" ,
90
+ } ) ;
91
+ createExport . resolves ( stubbedResponse ) ;
105
92
106
- expect ( stdout . getWritten ( ) ) . to . equal (
107
- `${ colorize ( stubbedResponse , { format : Format . JSON } ) } \n` ,
108
- ) ;
109
- } ) ;
93
+ await run (
94
+ `export create s3 --database '${ database } ' ${ args } --json` ,
95
+ container ,
96
+ ) ;
97
+ await stdout . waitForWritten ( ) ;
110
98
111
- it ( "passes the format to the account api" , async ( ) => {
112
- createExport . resolves ( createExportStub ( { format : "tagged" } ) ) ;
113
- await run (
114
- `export create s3 --database 'us-std/example' --bucket 'test-bucket' --path 'test/key' --format 'tagged'` ,
115
- container ,
116
- ) ;
117
- expect ( createExport ) . to . have . been . calledWith (
118
- sinon . match ( {
119
- format : "tagged" ,
120
- } ) ,
121
- ) ;
122
- } ) ;
99
+ expect ( stdout . getWritten ( ) ) . to . equal (
100
+ `${ colorize ( stubbedResponse , { format : Format . JSON } ) } \n` ,
101
+ ) ;
102
+ } ) ;
123
103
124
- it ( "should allow providing multiple collections" , async ( ) => {
125
- createExport . resolves ( createExportStub ( { collections : [ "foo" , "bar" ] } ) ) ;
126
- await run (
127
- `export create s3 --database 'us-std/example' --bucket 'test-bucket' --path 'test/key' --collection foo --collection bar` ,
128
- container ,
129
- ) ;
130
- expect ( createExport ) . to . have . been . calledWith (
131
- sinon . match ( {
132
- database : "us-std/example" ,
133
- collections : [ "foo" , "bar" ] ,
134
- } ) ,
135
- ) ;
136
- } ) ;
104
+ it ( `passes the format to the account api ${ description } ` , async ( ) => {
105
+ createExport . resolves ( createExportStub ( { format : "tagged" } ) ) ;
106
+ await run (
107
+ `export create s3 --database 'us-std/example' ${ args } --format 'tagged'` ,
108
+ container ,
109
+ ) ;
110
+ expect ( createExport ) . to . have . been . calledWith (
111
+ sinon . match ( {
112
+ format : "tagged" ,
113
+ } ) ,
114
+ ) ;
115
+ } ) ;
116
+
117
+ it ( `should allow providing multiple collections ${ description } ` , async ( ) => {
118
+ createExport . resolves (
119
+ createExportStub ( { collections : [ "foo" , "bar" ] } ) ,
120
+ ) ;
121
+ await run (
122
+ `export create s3 --database 'us-std/example' ${ args } --collection foo --collection bar` ,
123
+ container ,
124
+ ) ;
125
+ expect ( createExport ) . to . have . been . calledWith (
126
+ sinon . match ( {
127
+ database : "us-std/example" ,
128
+ collections : [ "foo" , "bar" ] ,
129
+ } ) ,
130
+ ) ;
131
+ } ) ;
132
+ } ,
133
+ ) ;
137
134
138
135
it ( "should output an error if --database is not provided" , async ( ) => {
136
+ const destination = "s3://test-bucket/test/key" ;
139
137
try {
140
- await run (
141
- "export create s3 --bucket test-bucket --path test/key" ,
142
- container ,
143
- ) ;
138
+ await run ( `export create s3 --destination '${ destination } '` , container ) ;
144
139
} catch { }
145
140
146
141
await stderr . waitForWritten ( ) ;
0 commit comments