@@ -41,54 +41,67 @@ describe("store-github", async () => {
41
41
assert . equal ( indiekit . publication . store . info . name , "user/repo on GitHub" ) ;
42
42
} ) ;
43
43
44
+ it ( "Checks if file exists" , async ( ) => {
45
+ assert . equal ( await github . fileExists ( "foo.txt" ) , true ) ;
46
+ assert . equal ( await github . fileExists ( "404.txt" ) , false ) ;
47
+ } ) ;
48
+
44
49
it ( "Creates file" , async ( ) => {
45
- const result = await github . createFile ( "foo.md " , "foobar " , {
50
+ const result = await github . createFile ( "new.txt " , "new " , {
46
51
message : "Message" ,
47
52
} ) ;
48
53
49
- assert . equal ( result , "https://github.com/user/repo/blob/main/foo.txt" ) ;
54
+ assert . equal ( result , "https://github.com/user/repo/blob/main/new.txt" ) ;
55
+ } ) ;
56
+
57
+ it ( "Doesn’t create file if already exists" , async ( ) => {
58
+ const result = await github . createFile ( "foo.txt" , "foo" , {
59
+ message : "Message" ,
60
+ } ) ;
61
+
62
+ assert . equal ( result , undefined ) ;
50
63
} ) ;
51
64
52
65
it ( "Throws error creating file" , async ( ) => {
53
66
await assert . rejects (
54
- github . createFile ( "401.md " , "foobar " , { message : "Message" } ) ,
67
+ github . createFile ( "401.txt " , "foo " , { message : "Message" } ) ,
55
68
( error ) => {
56
- assert ( error . message . includes ( "Could not create file 401.md " ) ) ;
69
+ assert ( error . message . includes ( "Could not create file 401.txt " ) ) ;
57
70
return true ;
58
71
} ,
59
72
) ;
60
73
} ) ;
61
74
62
75
it ( "Reads file" , async ( ) => {
63
- assert . equal ( await github . readFile ( "foo.md " ) , "foobar " ) ;
76
+ assert . equal ( await github . readFile ( "foo.txt " ) , "foo " ) ;
64
77
} ) ;
65
78
66
79
it ( "Throws error reading file" , async ( ) => {
67
- await assert . rejects ( github . readFile ( "404.md " ) , ( error ) => {
68
- assert ( error . message . includes ( "Could not read file 404.md " ) ) ;
80
+ await assert . rejects ( github . readFile ( "404.txt " ) , ( error ) => {
81
+ assert ( error . message . includes ( "Could not read file 404.txt " ) ) ;
69
82
return true ;
70
83
} ) ;
71
84
} ) ;
72
85
73
86
it ( "Updates file" , async ( ) => {
74
- const result = await github . updateFile ( "foo.md " , "foobar " , {
87
+ const result = await github . updateFile ( "foo.txt " , "foo " , {
75
88
message : "Message" ,
76
89
} ) ;
77
90
78
91
assert . equal ( result , "https://github.com/user/repo/blob/main/foo.txt" ) ;
79
92
} ) ;
80
93
81
94
it ( "Updates and renames file" , async ( ) => {
82
- const result = await github . updateFile ( "foo.md " , "qux" , {
95
+ const result = await github . updateFile ( "foo.txt " , "qux" , {
83
96
message : "Message" ,
84
- newPath : "bar.md " ,
97
+ newPath : "bar.txt " ,
85
98
} ) ;
86
99
87
100
assert . equal ( result , "https://github.com/user/repo/blob/main/bar.txt" ) ;
88
101
} ) ;
89
102
90
103
it ( "Creates file if original Not Found in repository" , async ( ) => {
91
- const result = await github . updateFile ( "bar.md " , "foobar " , {
104
+ const result = await github . updateFile ( "bar.txt " , "foo " , {
92
105
message : "Message" ,
93
106
} ) ;
94
107
@@ -97,33 +110,33 @@ describe("store-github", async () => {
97
110
98
111
it ( "Throws error updating file" , async ( ) => {
99
112
await assert . rejects (
100
- github . updateFile ( "401.md " , "foobar " , { message : "Message" } ) ,
113
+ github . updateFile ( "401.txt " , "foo " , { message : "Message" } ) ,
101
114
( error ) => {
102
- assert ( error . message . includes ( "Could not read file 401.md " ) ) ;
115
+ assert ( error . message . includes ( "Could not read file 401.txt " ) ) ;
103
116
return true ;
104
117
} ,
105
118
) ;
106
119
} ) ;
107
120
108
121
it ( "Deletes a file" , async ( ) => {
109
- assert . ok ( await github . deleteFile ( "foo.md " , { message : "Message" } ) ) ;
122
+ assert . ok ( await github . deleteFile ( "foo.txt " , { message : "Message" } ) ) ;
110
123
} ) ;
111
124
112
125
it ( "Throws error file Not Found in repository" , async ( ) => {
113
126
await assert . rejects (
114
- github . deleteFile ( "404.md " , { message : "Message" } ) ,
127
+ github . deleteFile ( "404.txt " , { message : "Message" } ) ,
115
128
( error ) => {
116
- assert ( error . message . includes ( "Could not read file 404.md " ) ) ;
129
+ assert ( error . message . includes ( "Could not read file 404.txt " ) ) ;
117
130
return true ;
118
131
} ,
119
132
) ;
120
133
} ) ;
121
134
122
135
it . skip ( "Throws error deleting a file" , async ( ) => {
123
136
await assert . rejects (
124
- github . deleteFile ( "401.md " , { message : "Message" } ) ,
137
+ github . deleteFile ( "401.txt " , { message : "Message" } ) ,
125
138
( error ) => {
126
- assert ( error . message . includes ( "Could not delete file 401.md " ) ) ;
139
+ assert ( error . message . includes ( "Could not delete file 401.txt " ) ) ;
127
140
return true ;
128
141
} ,
129
142
) ;
0 commit comments