Add error checking to client-side permalink service

This commit is contained in:
Rohan Mitchell
2015-07-10 09:41:03 +10:00
parent 73b90dba10
commit 197c99349d
2 changed files with 41 additions and 7 deletions

View File

@@ -1,6 +1,10 @@
describe "Permalink Checker service", ->
PermalinkChecker = null
$httpBackend = null
permalink = "this-is-a-permalink"
permalink_too_long = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
permalink_invalid_chars = "<html>"
beforeEach ->
module 'admin.enterprises'
@@ -8,7 +12,31 @@ describe "Permalink Checker service", ->
$httpBackend = _$httpBackend_
PermalinkChecker = $injector.get("PermalinkChecker")
it "sends an http request to check the permalink", ->
permalink = "this-is-a-permalink"
$httpBackend.expectGET "/enterprises/check_permalink?permalink=#{permalink}"
PermalinkChecker.check(permalink)
it "responds to available permalinks", ->
$httpBackend.expectGET("/enterprises/check_permalink?permalink=#{permalink}").respond permalink
PermalinkChecker.check(permalink).then (data) ->
expect(data.permalink).toEqual permalink
expect(data.available).toEqual "Available"
$httpBackend.flush()
it "responds to unavailable permalinks", ->
$httpBackend.expectGET("/enterprises/check_permalink?permalink=#{permalink}").respond 409, permalink
PermalinkChecker.check(permalink).then (data) ->
expect(data.permalink).toEqual permalink
expect(data.available).toEqual "Unavailable"
$httpBackend.flush()
describe "invalid data", ->
it "errors for permalinks that are too long", ->
$httpBackend.expectGET("/enterprises/check_permalink?permalink=#{permalink}").respond permalink_too_long
PermalinkChecker.check(permalink).then (data) ->
expect(data.permalink).toEqual permalink
expect(data.available).toEqual "Error"
$httpBackend.flush()
it "errors for permalinks that contain invalid characters", ->
$httpBackend.expectGET("/enterprises/check_permalink?permalink=#{permalink}").respond permalink_invalid_chars
PermalinkChecker.check(permalink).then (data) ->
expect(data.permalink).toEqual permalink
expect(data.available).toEqual "Error"
$httpBackend.flush()