@@ -46,6 +46,20 @@ describe("store-bitbucket", () => {
46
46
) ;
47
47
} ) ;
48
48
49
+ it ( "Checks if file exists" , async ( ) => {
50
+ nock ( bitbucketUrl )
51
+ . get ( "/2.0/repositories/username/repo/src/main/foo.txt" )
52
+ . query ( { format : "meta" } )
53
+ . reply ( 201 , { path : "foo.txt" , type : "meta" } ) ;
54
+ nock ( bitbucketUrl )
55
+ . post ( "/2.0/repositories/username/repo/src/main/bar.txt" )
56
+ . query ( { format : "meta" } )
57
+ . replyWithError ( "Not found" ) ;
58
+
59
+ assert . equal ( await bitbucket . fileExists ( "foo.txt" ) , true ) ;
60
+ assert . equal ( await bitbucket . fileExists ( "bar.txt" ) , false ) ;
61
+ } ) ;
62
+
49
63
it ( "Creates file" , async ( ) => {
50
64
nock ( bitbucketUrl ) . post ( "/2.0/repositories/username/repo/src" ) . reply ( 201 , {
51
65
"content-type" : "application/json" ,
@@ -58,6 +72,29 @@ describe("store-bitbucket", () => {
58
72
assert . equal ( result , "https://bitbucket.org/username/repo/foo.txt" ) ;
59
73
} ) ;
60
74
75
+ it ( "Doesn’t create file if already exists" , async ( ) => {
76
+ nock ( bitbucketUrl ) . post ( "/2.0/repositories/username/repo/src" ) . reply ( 201 , {
77
+ "content-type" : "application/json" ,
78
+ } ) ;
79
+
80
+ // Create file
81
+ await bitbucket . createFile ( "foo.txt" , "foo" , {
82
+ message : "Message" ,
83
+ } ) ;
84
+
85
+ nock ( bitbucketUrl )
86
+ . get ( "/2.0/repositories/username/repo/src/main/foo.txt" )
87
+ . query ( { format : "meta" } )
88
+ . reply ( 201 , { path : "foo.txt" , type : "meta" } ) ;
89
+
90
+ // Create file a second time
91
+ const result = await bitbucket . createFile ( "foo.txt" , "foo" , {
92
+ message : "Message" ,
93
+ } ) ;
94
+
95
+ assert . equal ( result , undefined ) ;
96
+ } ) ;
97
+
61
98
it ( "Throws error creating file" , async ( ) => {
62
99
nock ( bitbucketUrl )
63
100
. post ( "/2.0/repositories/username/repo/src" )
0 commit comments