overleaf/services/web/test/smoke/coffee/SmokeTests.coffee

73 lines
2.4 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
chai = require("chai")
chai.should()
expect = chai.expect
Settings = require "settings-sharelatex"
# Monkey patch request cookies, because the new tough-cookie module
# assumes it's not a secure cookie if the url is not HTTPS
request = require "request"
jar = request.jar()
jar.getCookieString = (uri) ->
return @_jar.getCookieStringSync uri, secure: true
request = request.defaults jar: jar
2014-02-12 05:23:40 -05:00
port = Settings.internal?.web?.port or Settings.port or 3000
buildUrl = (path) -> "http://localhost:#{port}/#{path}"
describe "Opening", ->
before (done) ->
request.get {
url: buildUrl("register")
headers:
"X-Forwarded-Proto": "https"
}, (error, response, body) =>
csrf = body.match("<input name=\"_csrf\" type=\"hidden\" value=\"(.*?)\">")[1]
request.post {
url: buildUrl("register")
form:
email: Settings.smokeTest.user
password: Settings.smokeTest.password
_csrf: csrf
headers:
"X-Forwarded-Proto": "https"
}, (error, response, body) ->
throw error if error?
done()
2014-05-19 06:53:10 -04:00
after (done)->
request.get {
url: buildUrl("logout")
headers:
"X-Forwarded-Proto": "https"
}, (error, response, body) =>
throw error if error?
done()
2014-02-12 05:23:40 -05:00
it "a project", (done) ->
request {
url: buildUrl("project/#{Settings.smokeTest.projectId}")
headers:
"X-Forwarded-Proto": "https"
}, (error, response, body) ->
expect(error, "smoke test: error in getting project").to.not.exist
expect(response.statusCode, "smoke test: response code is not 200 getting project").to.equal(200)
2014-02-12 05:23:40 -05:00
# Check that the project id is present in the javascript that loads up the project
2014-07-08 09:29:06 -04:00
match = !!body.match("window.project_id = \"#{Settings.smokeTest.projectId}\"")
expect(match, "smoke test: project page html does not have project_id").to.equal true
2014-02-12 05:23:40 -05:00
done()
it "the project list", (done) ->
request {
url: buildUrl("project")
headers:
"X-Forwarded-Proto": "https"
}, (error, response, body) ->
expect(error, "smoke test: error returned in getting project list").to.not.exist
2014-04-01 06:14:31 -04:00
expect(response.statusCode, "smoke test: response code is not 200 getting project list").to.equal(200)
2014-08-06 06:50:19 -04:00
expect(!!body.match("<title>Your Projects - ShareLaTeX, the Online LaTeX Editor</title>"), "smoke test: body does not have correct title").to.equal true
2014-07-08 09:29:06 -04:00
expect(!!body.match("ProjectPageController"), "smoke test: body does not have correct angular controller").to.equal true
2014-02-12 05:23:40 -05:00
done()