2121
2222package github4s .unit
2323
24- import github4s .api .{ Auth , Gists , Repos , Users }
24+ import github4s .api ._
2525import github4s .free .domain .{GistFile , Pagination }
2626import github4s .utils .{DummyGithubUrls , MockGithubApiServer , TestUtils }
2727import org .scalatest ._
@@ -39,10 +39,11 @@ class ApiSpec
3939 with DummyGithubUrls
4040 with ImplicitsJVM {
4141
42- val auth = new Auth [HttpResponse [String ], Id ]
43- val repos = new Repos [HttpResponse [String ], Id ]
44- val users = new Users [HttpResponse [String ], Id ]
45- val gists = new Gists [HttpResponse [String ], Id ]
42+ val auth = new Auth [HttpResponse [String ], Id ]
43+ val repos = new Repos [HttpResponse [String ], Id ]
44+ val users = new Users [HttpResponse [String ], Id ]
45+ val gists = new Gists [HttpResponse [String ], Id ]
46+ val gitData = new GitData [HttpResponse [String ], Id ]
4647
4748 " Auth >> NewAuth" should " return a valid token when valid credential is provided" in {
4849 val response = auth.newAuth(
@@ -289,4 +290,158 @@ class ApiSpec
289290
290291 }
291292
293+ " GitData >> GetReference" should " return the single reference" in {
294+ val response =
295+ gitData.reference(
296+ accessToken,
297+ headerUserAgent,
298+ validRepoOwner,
299+ validRepoName,
300+ validRefSingle)
301+ response should be(' right )
302+
303+ response.toOption map { r =>
304+ r.statusCode shouldBe okStatusCode
305+ }
306+ }
307+
308+ it should " return multiple references" in {
309+ val response =
310+ gitData.reference(
311+ accessToken,
312+ headerUserAgent,
313+ validRepoOwner,
314+ validRepoName,
315+ validRefMultiple)
316+ response should be(' right )
317+
318+ response.toOption map { r =>
319+ r.statusCode shouldBe okStatusCode
320+ }
321+ }
322+
323+ it should " return error Left for non existent reference" in {
324+ val response =
325+ gitData.reference(accessToken, headerUserAgent, validRepoOwner, validRepoName, invalidRef)
326+ response should be(' left )
327+ }
328+
329+ " GitData >> UpdateReference" should " return the single reference" in {
330+ val response =
331+ gitData.updateReference(
332+ accessToken,
333+ headerUserAgent,
334+ validRepoOwner,
335+ validRepoName,
336+ validRefSingle,
337+ validCommitSha)
338+ response should be(' right )
339+
340+ response.toOption map { r =>
341+ r.statusCode shouldBe okStatusCode
342+ }
343+ }
344+
345+ it should " return error Left for non authenticated request" in {
346+ val response =
347+ gitData.updateReference(
348+ None ,
349+ headerUserAgent,
350+ validRepoOwner,
351+ validRepoName,
352+ validRefSingle,
353+ validCommitSha)
354+ response should be(' left )
355+ }
356+
357+ " GitData >> GetCommit" should " return the single commit" in {
358+ val response =
359+ gitData.commit(accessToken, headerUserAgent, validRepoOwner, validRepoName, validCommitSha)
360+ response should be(' right )
361+
362+ response.toOption map { r =>
363+ r.statusCode shouldBe okStatusCode
364+ }
365+ }
366+
367+ it should " return error Left for non existent commit" in {
368+ val response =
369+ gitData.commit(accessToken, headerUserAgent, validRepoOwner, validRepoName, invalidCommitSha)
370+ response should be(' left )
371+ }
372+
373+ " GitData >> CreateCommit" should " return the single commit" in {
374+ val response =
375+ gitData.createCommit(
376+ accessToken,
377+ headerUserAgent,
378+ validRepoOwner,
379+ validRepoName,
380+ validNote,
381+ validTreeSha,
382+ List (validCommitSha))
383+ response should be(' right )
384+
385+ response.toOption map { r =>
386+ r.statusCode shouldBe createdStatusCode
387+ }
388+ }
389+
390+ it should " return error Left for non authenticated request" in {
391+ val response =
392+ gitData.createCommit(
393+ None ,
394+ headerUserAgent,
395+ validRepoOwner,
396+ validRepoName,
397+ validNote,
398+ validTreeSha,
399+ List (validCommitSha))
400+ response should be(' left )
401+ }
402+
403+ " GitData >> CreateBlob" should " return the created blob" in {
404+ val response =
405+ gitData.createBlob(accessToken, headerUserAgent, validRepoOwner, validRepoName, validNote)
406+ response should be(' right )
407+
408+ response.toOption map { r =>
409+ r.statusCode shouldBe createdStatusCode
410+ }
411+ }
412+
413+ it should " return error Left for non authenticated request" in {
414+ val response =
415+ gitData.createBlob(None , headerUserAgent, validRepoOwner, validRepoName, validNote)
416+ response should be(' left )
417+ }
418+
419+ " GitData >> CreateTree" should " return the created tree" in {
420+ val response =
421+ gitData.createTree(
422+ accessToken,
423+ headerUserAgent,
424+ validRepoOwner,
425+ validRepoName,
426+ Some (validTreeSha),
427+ treeDataList)
428+ response should be(' right )
429+
430+ response.toOption map { r =>
431+ r.statusCode shouldBe createdStatusCode
432+ }
433+ }
434+
435+ it should " return error Left for non authenticated request" in {
436+ val response =
437+ gitData.createTree(
438+ None ,
439+ headerUserAgent,
440+ validRepoOwner,
441+ validRepoName,
442+ Some (validTreeSha),
443+ treeDataList)
444+ response should be(' left )
445+ }
446+
292447}
0 commit comments