mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add error checking to client-side permalink service
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user