|
|
@@ -1,5 +1,6 @@
|
|
|
async = require "async"
|
|
|
expect = require("chai").expect
|
|
|
+_ = require 'underscore'
|
|
|
|
|
|
MockFileStoreApi = require './helpers/MockFileStoreApi'
|
|
|
MockURLSource = require './helpers/MockURLSource'
|
|
|
@@ -92,3 +93,87 @@ describe "LinkedFiles", ->
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
expect(body).to.equal "bar bar bar"
|
|
|
done()
|
|
|
+
|
|
|
+ it "should return an error if the URL does not succeed", (done) ->
|
|
|
+ @owner.request.post {
|
|
|
+ url: "/project/#{@project_id}/linked_file",
|
|
|
+ json:
|
|
|
+ provider: 'url'
|
|
|
+ data: {
|
|
|
+ url: "http://localhost:6543/does-not-exist"
|
|
|
+ }
|
|
|
+ parent_folder_id: @root_folder_id
|
|
|
+ name: 'url-test-file-3'
|
|
|
+ }, (error, response, body) =>
|
|
|
+ throw error if error?
|
|
|
+ expect(response.statusCode).to.equal 422 # unprocessable
|
|
|
+ expect(body).to.equal(
|
|
|
+ "Your URL could not be reached (404 status code). Please check it and try again."
|
|
|
+ )
|
|
|
+ done()
|
|
|
+
|
|
|
+ it "should return an error if the URL is invalid", (done) ->
|
|
|
+ @owner.request.post {
|
|
|
+ url: "/project/#{@project_id}/linked_file",
|
|
|
+ json:
|
|
|
+ provider: 'url'
|
|
|
+ data: {
|
|
|
+ url: "!^$%"
|
|
|
+ }
|
|
|
+ parent_folder_id: @root_folder_id
|
|
|
+ name: 'url-test-file-4'
|
|
|
+ }, (error, response, body) =>
|
|
|
+ throw error if error?
|
|
|
+ expect(response.statusCode).to.equal 422 # unprocessable
|
|
|
+ expect(body).to.equal(
|
|
|
+ "Your URL is not valid. Please check it and try again."
|
|
|
+ )
|
|
|
+ done()
|
|
|
+
|
|
|
+ it "should return an error if the URL uses a non-http protocol", (done) ->
|
|
|
+ @owner.request.post {
|
|
|
+ url: "/project/#{@project_id}/linked_file",
|
|
|
+ json:
|
|
|
+ provider: 'url'
|
|
|
+ data: {
|
|
|
+ url: "ftp://localhost"
|
|
|
+ }
|
|
|
+ parent_folder_id: @root_folder_id
|
|
|
+ name: 'url-test-file-5'
|
|
|
+ }, (error, response, body) =>
|
|
|
+ throw error if error?
|
|
|
+ expect(response.statusCode).to.equal 422 # unprocessable
|
|
|
+ expect(body).to.equal(
|
|
|
+ "Your URL is not valid. Please check it and try again."
|
|
|
+ )
|
|
|
+ done()
|
|
|
+
|
|
|
+ it "should accept a URL withuot a leading http://, and add it", (done) ->
|
|
|
+ @owner.request.post {
|
|
|
+ url: "/project/#{@project_id}/linked_file",
|
|
|
+ json:
|
|
|
+ provider: 'url'
|
|
|
+ data: {
|
|
|
+ url: "http://localhost:6543/foo"
|
|
|
+ }
|
|
|
+ parent_folder_id: @root_folder_id
|
|
|
+ name: 'url-test-file-6'
|
|
|
+ }, (error, response, body) =>
|
|
|
+ throw error if error?
|
|
|
+ expect(response.statusCode).to.equal 204
|
|
|
+ @owner.getProject @project_id, (error, project) =>
|
|
|
+ throw error if error?
|
|
|
+ file = _.find project.rootFolder[0].fileRefs, (file) ->
|
|
|
+ file.name == 'url-test-file-6'
|
|
|
+ expect(file.linkedFileData).to.deep.equal({
|
|
|
+ provider: 'url'
|
|
|
+ url: "http://localhost:6543/foo"
|
|
|
+ })
|
|
|
+ @owner.request.get "/project/#{@project_id}/file/#{file._id}", (error, response, body) ->
|
|
|
+ throw error if error?
|
|
|
+ expect(response.statusCode).to.equal 200
|
|
|
+ expect(body).to.equal "foo foo foo"
|
|
|
+ done()
|
|
|
+
|
|
|
+ # TODO: Add test for asking for host that return ENOTFOUND
|
|
|
+ # (This will probably end up handled by the proxy)
|