Files
cypress/packages/server/test/unit/user_spec.coffee
T
Brian Mann 4b368830fa send array of specs to API + platform (#1682)
* WIP: refactor runs and recordings, update to new API updates, iteratively send spec results [skip ci]

* update / add schema deps

* add takenAt to screenshots payload

* WIP: refactor recordings to send correctly payloads, iterative through each spec, error handling, e2e tests

* add missing properties, remove hacks, upload stdout, passing tests

* normalize wall clock for newest schema spec

* rename projectPath -> projectRoot for clarity

* normalize specPattern to be relative to projectRoot

* comment out lib/api debug code

* WIP fixes a lot of failing tests

* many more tests around recording

* WIP: update to use x-os-name on all instead of platform

* WIP: update to route version 4 for creating instances

* server: upgrade json-schemas to 4.7.2

* remove debug logs

* fix stdout not being restored correctly between specs

* test all the edge cases with failed api interactions and early exits

* add e2e tests around recording without projectID

* add e2e tests around recording without recordKey

* refactored all tests surrounding record mode, removed duplicates, tested only edge cases

* fixes #1692

* fix failing unit tests, bump schemas

* bump sinon, replace custom sandbox

* fix sinon@5 not restoring fake timers automatically

* missing e2e record snapshots

* fix failing tests, don't pass config through each run, remove old timings in favor of spec isolation

* more e2e test fixes

* add e2e tests around uploading artifacts, fix bug with not uploading videos when it should

- cleanup some dead code
- add debug logs

* cleanup dead code, remove notion of failingTests
2018-05-13 20:24:46 -04:00

77 lines
2.6 KiB
CoffeeScript

require("../spec_helper")
api = require("#{root}lib/api")
cache = require("#{root}lib/cache")
user = require("#{root}lib/user")
errors = require("#{root}lib/errors")
describe "lib/user", ->
context ".get", ->
it "calls cache.getUser", ->
sinon.stub(cache, "getUser").resolves({name: "brian"})
user.get().then (user) ->
expect(user).to.deep.eq({name: "brian"})
context ".logIn", ->
it "sets user to cache + returns user", ->
obj = {name: "brian"}
sinon.stub(api, "createSignin").withArgs("abc-123").resolves(obj)
sinon.spy(cache, "setUser")
user.logIn("abc-123").then (ret) ->
expect(ret).to.deep.eq(obj)
expect(cache.setUser).to.be.calledWith(obj)
context ".logOut", ->
it "calls api.createSignout + removes the session from cache", ->
sinon.stub(api, "createSignout").withArgs("abc-123").resolves()
sinon.stub(cache, "getUser").resolves({name: "brian", authToken: "abc-123"})
sinon.spy(cache, "removeUser")
user.logOut().then ->
expect(cache.removeUser).to.be.calledOnce
it "does not send to api.createSignout without a authToken", ->
sinon.spy(api, "createSignout")
sinon.stub(cache, "getUser").resolves({name: "brian"})
sinon.spy(cache, "removeUser")
user.logOut().then ->
expect(api.createSignout).not.to.be.called
expect(cache.removeUser).to.be.calledOnce
it "removes the session from cache even if api.createSignout rejects", ->
sinon.stub(api, "createSignout").withArgs("abc-123").rejects(new Error("ECONNREFUSED"))
sinon.stub(cache, "getUser").resolves({name: "brian", authToken: "abc-123"})
sinon.spy(cache, "removeUser")
user.logOut().catch ->
expect(cache.removeUser).to.be.calledOnce
context ".getLoginUrl", ->
it "calls api.getLoginUrl", ->
sinon.stub(api, "getLoginUrl").resolves("https://github.com/login")
user.getLoginUrl().then (url) ->
expect(url).to.eq("https://github.com/login")
context ".ensureAuthToken", ->
it "returns authToken", ->
sinon.stub(cache, "getUser").resolves({name: "brian", authToken: "abc-123"})
user.ensureAuthToken().then (st) ->
expect(st).to.eq("abc-123")
it "throws NOT_LOGGED_IN when no authToken, tagged as api error", ->
sinon.stub(cache, "getUser").resolves(null)
user.ensureAuthToken()
.then ->
throw new Error("should have thrown an error")
.catch (err) ->
expectedErr = errors.get("NOT_LOGGED_IN")
expect(err.message).to.eq(expectedErr.message)
expect(err.isApiError).to.be.true
expect(err.type).to.eq(expectedErr.type)