@@ -38,6 +38,7 @@ const createMockOctokit = () =>
38
38
describe ( "ensureRepositoryExists" , ( ) => {
39
39
it ( "returns the repository when octokit is undefined" , async ( ) => {
40
40
const actual = await ensureRepositoryExists ( undefined , {
41
+ mode : "initialize" ,
41
42
owner,
42
43
repository,
43
44
} ) ;
@@ -51,6 +52,7 @@ describe("ensureRepositoryExists", () => {
51
52
const actual = await ensureRepositoryExists (
52
53
{ auth, octokit } ,
53
54
{
55
+ mode : "initialize" ,
54
56
owner,
55
57
repository,
56
58
} ,
@@ -67,10 +69,7 @@ describe("ensureRepositoryExists", () => {
67
69
68
70
const actual = await ensureRepositoryExists (
69
71
{ auth, octokit } ,
70
- {
71
- owner,
72
- repository,
73
- } ,
72
+ { mode : "initialize" , owner, repository } ,
74
73
) ;
75
74
76
75
expect ( actual ) . toEqual ( { github : { auth, octokit } , repository } ) ;
@@ -82,6 +81,26 @@ describe("ensureRepositoryExists", () => {
82
81
} ) ;
83
82
} ) ;
84
83
84
+ it ( "defaults to creating a repository when mode is 'create'" , async ( ) => {
85
+ const octokit = createMockOctokit ( ) ;
86
+
87
+ mockDoesRepositoryExist . mockResolvedValue ( false ) ;
88
+
89
+ const actual = await ensureRepositoryExists (
90
+ { auth, octokit } ,
91
+ { mode : "create" , owner, repository } ,
92
+ ) ;
93
+
94
+ expect ( actual ) . toEqual ( { github : { auth, octokit } , repository } ) ;
95
+ expect ( octokit . rest . repos . createUsingTemplate ) . toHaveBeenCalledWith ( {
96
+ name : repository ,
97
+ owner,
98
+ template_owner : "JoshuaKGoldberg" ,
99
+ template_repo : "create-typescript-app" ,
100
+ } ) ;
101
+ expect ( mockSelect ) . not . toHaveBeenCalled ( ) ;
102
+ } ) ;
103
+
85
104
it ( "returns the second repository when the prompt is 'different', the first repository does not exist, and the second repository exists" , async ( ) => {
86
105
const octokit = createMockOctokit ( ) ;
87
106
const newRepository = "new-repository" ;
@@ -94,10 +113,7 @@ describe("ensureRepositoryExists", () => {
94
113
95
114
const actual = await ensureRepositoryExists (
96
115
{ auth, octokit } ,
97
- {
98
- owner,
99
- repository,
100
- } ,
116
+ { mode : "initialize" , owner, repository } ,
101
117
) ;
102
118
103
119
expect ( actual ) . toEqual ( {
@@ -119,10 +135,7 @@ describe("ensureRepositoryExists", () => {
119
135
120
136
const actual = await ensureRepositoryExists (
121
137
{ auth, octokit } ,
122
- {
123
- owner,
124
- repository,
125
- } ,
138
+ { mode : "initialize" , owner, repository } ,
126
139
) ;
127
140
128
141
expect ( actual ) . toEqual ( {
@@ -145,10 +158,7 @@ describe("ensureRepositoryExists", () => {
145
158
146
159
const actual = await ensureRepositoryExists (
147
160
{ auth, octokit } ,
148
- {
149
- owner,
150
- repository,
151
- } ,
161
+ { mode : "initialize" , owner, repository } ,
152
162
) ;
153
163
154
164
expect ( actual ) . toEqual ( { octokit : undefined , repository } ) ;
0 commit comments