@@ -312,7 +312,6 @@ func WipObjectSpec(ctx context.Context, urlStr string) func(c convey.C) {
312312 })
313313
314314 c .Convey ("get wip changes" , func (c convey.C ) {
315-
316315 c .Convey ("no auth" , func () {
317316 re := client .RequestEditors
318317 client .RequestEditors = nil
@@ -381,5 +380,80 @@ func WipObjectSpec(ctx context.Context, urlStr string) func(c convey.C) {
381380 convey .So (* result .JSON200 , convey .ShouldHaveLength , 4 )
382381 })
383382 })
383+
384+ c .Convey ("revert wip changes" , func (c convey.C ) {
385+ c .Convey ("no auth" , func () {
386+ re := client .RequestEditors
387+ client .RequestEditors = nil
388+ resp , err := client .RevertWipChanges (ctx , userName , repoName , & api.RevertWipChangesParams {
389+ RefName : branchName ,
390+ })
391+ client .RequestEditors = re
392+ convey .So (err , convey .ShouldBeNil )
393+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusUnauthorized )
394+ })
395+
396+ c .Convey ("fail to revert changes in non exit user" , func () {
397+ resp , err := client .RevertWipChanges (ctx , "mockUser" , repoName , & api.RevertWipChangesParams {
398+ RefName : branchName ,
399+ })
400+ convey .So (err , convey .ShouldBeNil )
401+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
402+ })
403+
404+ c .Convey ("fail to revert changes in non exit repo" , func () {
405+ resp , err := client .RevertWipChanges (ctx , userName , "fakeRepo" , & api.RevertWipChangesParams {
406+ RefName : branchName ,
407+ })
408+ convey .So (err , convey .ShouldBeNil )
409+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
410+ })
411+
412+ c .Convey ("fail to revert changes in non exit branch" , func () {
413+ resp , err := client .RevertWipChanges (ctx , userName , repoName , & api.RevertWipChangesParams {
414+ RefName : "mockref" ,
415+ })
416+ convey .So (err , convey .ShouldBeNil )
417+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
418+ })
419+
420+ c .Convey ("forbidden revert changes in others" , func () {
421+ resp , err := client .RevertWipChanges (ctx , "jimmy" , "happygo" , & api.RevertWipChangesParams {
422+ RefName : branchName ,
423+ })
424+ convey .So (err , convey .ShouldBeNil )
425+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusForbidden )
426+ })
427+
428+ c .Convey ("not exit path" , func () {
429+ resp , err := client .RevertWipChanges (ctx , userName , repoName , & api.RevertWipChangesParams {
430+ RefName : branchName ,
431+ PathPrefix : utils .String ("a/b/c/d" ),
432+ })
433+ convey .So (err , convey .ShouldBeNil )
434+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
435+ })
436+
437+ c .Convey ("success to revert changes" , func () {
438+ resp , err := client .RevertWipChanges (ctx , userName , repoName , & api.RevertWipChangesParams {
439+ RefName : branchName ,
440+ })
441+ convey .So (err , convey .ShouldBeNil )
442+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusOK )
443+
444+ {
445+ resp , err = client .GetWipChanges (ctx , userName , repoName , & api.GetWipChangesParams {
446+ RefName : branchName ,
447+ })
448+ convey .So (err , convey .ShouldBeNil )
449+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusOK )
450+
451+ result , err := api .ParseGetWipChangesResponse (resp )
452+ convey .So (err , convey .ShouldBeNil )
453+ convey .So (* result .JSON200 , convey .ShouldHaveLength , 0 )
454+ }
455+ })
456+ })
457+
384458 }
385459}
0 commit comments