@@ -9,7 +9,7 @@ import {getClient, userAsync} from '../../src/repositories/bitbucketrepo.js';
9
9
10
10
describe ( 'repositories/bitbucketrepo.js' , ( ) => {
11
11
const workspace = 'threat-workspace' ;
12
- const repoPath = 'ThreatDragonModels'
12
+ const repoPath = 'ThreatDragonModels' ;
13
13
14
14
const info = {
15
15
body : {
@@ -19,6 +19,8 @@ describe('repositories/bitbucketrepo.js', () => {
19
19
branch : 'testBranch' ,
20
20
organisation : 'test org' ,
21
21
page : 'testPage' ,
22
+ repo : 'test repo' ,
23
+ ref : 'testRef' ,
22
24
listBranches : {
23
25
workspace : workspace ,
24
26
repo_slug : 'repoInfo.repo' ,
@@ -68,7 +70,8 @@ describe('repositories/bitbucketrepo.js', () => {
68
70
values : [
69
71
{ full_name : 'Threat-Workspace/Repo1' } ,
70
72
{ full_name : 'Threat-Workspace/Repo2' } ,
71
- { full_name : 'Threat-Workspace/Repo3' } , ]
73
+ { full_name : 'Threat-Workspace/Repo3' } ,
74
+ ]
72
75
}
73
76
} ) ) ,
74
77
getBranch : sinon . stub ( ) . returns ( Promise . resolve ( { data : { target : { hash : info . readInfo . commit } } } ) ) ,
@@ -82,6 +85,9 @@ describe('repositories/bitbucketrepo.js', () => {
82
85
users : {
83
86
getAuthedUser : sinon . stub ( ) . returns ( Promise . resolve ( { data : { id : 1 , username : 'Test User' } } ) ) ,
84
87
} ,
88
+ refs :{
89
+ createBranch : sinon . stub ( ) . returns ( Promise . resolve ( { data : { values : [ ] } } ) ) ,
90
+ }
85
91
} ;
86
92
87
93
const clientOptions = {
@@ -124,7 +130,7 @@ describe('repositories/bitbucketrepo.js', () => {
124
130
} ) ;
125
131
126
132
it ( 'creates the bitbucket client' , ( ) => {
127
- threatModelRepository . userAsync ( accessToken )
133
+ threatModelRepository . userAsync ( accessToken ) ;
128
134
sinon . stub ( env , 'get' ) . returns ( { config : { BITBUCKET_WORKSPACE : workspace } } ) ;
129
135
expect ( BitbucketClientWrapper . getClient ) . to . have . been . calledWith ( clientOptions ) ;
130
136
@@ -146,7 +152,7 @@ describe('repositories/bitbucketrepo.js', () => {
146
152
} ) ;
147
153
148
154
// Setup the transformed data
149
- let transformedReposData = [
155
+ const transformedReposData = [
150
156
{ full_name : 'repo1' } ,
151
157
{ full_name : 'repo2' } ,
152
158
{ full_name : 'repo3' } ,
@@ -163,7 +169,7 @@ describe('repositories/bitbucketrepo.js', () => {
163
169
} ) ;
164
170
165
171
describe ( 'branchesAsync' , ( ) => {
166
- let repoInfo = { page : info . listBranches . page , repo : info . listBranches . repo_slug }
172
+ const repoInfo = { page : info . listBranches . page , repo : info . listBranches . repo_slug } ;
167
173
168
174
beforeEach ( async ( ) => {
169
175
sinon . stub ( env , 'get' ) . returns ( { config : { BITBUCKET_WORKSPACE : workspace } } ) ;
@@ -181,13 +187,15 @@ describe('repositories/bitbucketrepo.js', () => {
181
187
} ) ;
182
188
183
189
describe ( 'modelsAsync' , ( ) => {
184
- let branchInfo = { branch : info . branchInfo . name , repo : info . branchInfo . repo_slug } ;
190
+ const branchInfo = { branch : info . branchInfo . name , repo : info . branchInfo . repo_slug } ;
185
191
186
192
beforeEach ( async ( ) => {
187
193
sinon . stub ( env , 'get' ) . returns ( { config : { BITBUCKET_WORKSPACE : workspace , BITBUCKET_REPO_ROOT_DIRECTORY : repoPath } } ) ;
188
- sinon . stub ( mockClient . source , 'read' ) . returns ( Promise . resolve ( { data : { values : [ { path : 'ThreatDragonModels/model1' } ,
194
+ sinon . stub ( mockClient . source , 'read' ) . returns ( Promise . resolve ( { data : { values : [
195
+ { path : 'ThreatDragonModels/model1' } ,
189
196
{ path : 'ThreatDragonModels/model2' } ,
190
- { path : 'ThreatDragonModels/model3' } ] } } ) ) ;
197
+ { path : 'ThreatDragonModels/model3' }
198
+ ] } } ) ) ;
191
199
await threatModelRepository . modelsAsync ( branchInfo , accessToken ) ;
192
200
} ) ;
193
201
@@ -222,7 +230,7 @@ describe('repositories/bitbucketrepo.js', () => {
222
230
} ) ;
223
231
224
232
describe ( 'modelAsync' , ( ) => {
225
- let modelInfo = { branch : info . modelInfo . name , repo : info . modelInfo . repo_slug , model : info . modelInfo . model } ;
233
+ const modelInfo = { branch : info . modelInfo . name , repo : info . modelInfo . repo_slug , model : info . modelInfo . model } ;
226
234
227
235
beforeEach ( async ( ) => {
228
236
sinon . stub ( env , 'get' ) . returns ( { config : { BITBUCKET_WORKSPACE : workspace , BITBUCKET_REPO_ROOT_DIRECTORY : repoPath } } ) ;
@@ -245,14 +253,14 @@ describe('repositories/bitbucketrepo.js', () => {
245
253
} ) ;
246
254
247
255
describe ( 'createAsync' , ( ) => {
248
- let createAysncInfo = {
256
+ const createAysncInfo = {
249
257
branch : info . createAsync . name ,
250
258
repo : info . createAsync . repo_slug ,
251
259
model : info . createAsync . model ,
252
260
body : info . createAsync . body
253
261
} ;
254
262
255
- let createFileCommitInfo = {
263
+ const createFileCommitInfo = {
256
264
'ThreatDragonModels/my model/my model.json' : JSON . stringify ( createAysncInfo . body , null , ' ' ) ,
257
265
repo_slug : createAysncInfo . repo ,
258
266
files : 'ThreatDragonModels/my model/my model.json' ,
@@ -280,14 +288,14 @@ describe('repositories/bitbucketrepo.js', () => {
280
288
281
289
describe ( 'updateAsync' , ( ) => {
282
290
283
- let updateAysncInfo = {
291
+ const updateAysncInfo = {
284
292
branch : info . createAsync . name ,
285
293
repo : info . createAsync . repo_slug ,
286
294
model : info . createAsync . model ,
287
295
body : info . createAsync . body
288
296
} ;
289
297
290
- let updateFileCommitInfo = {
298
+ const updateFileCommitInfo = {
291
299
'ThreatDragonModels/my model/my model.json' : JSON . stringify ( updateAysncInfo . body , null , ' ' ) ,
292
300
repo_slug : updateAysncInfo . repo ,
293
301
files : 'ThreatDragonModels/my model/my model.json' ,
@@ -324,6 +332,21 @@ describe('repositories/bitbucketrepo.js', () => {
324
332
325
333
} ) ;
326
334
335
+ describe ( 'create branch' , ( ) => {
336
+ beforeEach ( async ( ) => {
337
+ sinon . stub ( env , 'get' ) . returns ( { config : { BITBUCKET_WORKSPACE : workspace , BITBUCKET_REPO_ROOT_DIRECTORY : repoPath } } ) ;
338
+ await threatModelRepository . createBranchAsync ( info , accessToken ) ;
339
+ } ) ;
340
+ it ( 'creates a new branch' , ( ) => {
341
+ expect ( mockClient . refs . createBranch ) . to . have . been . calledWith (
342
+ {
343
+ _body : { name : info . branch , target : { hash : info . ref } } ,
344
+ repo_slug : info . repo ,
345
+ workspace : workspace
346
+ }
347
+ ) ;
348
+ } ) ;
349
+ } ) ;
327
350
328
351
} ) ;
329
352
0 commit comments