     rootScope = _$rootScope_
 
   it "should change user when signing in and out", ->
-    userCredentials = { email: "user@localhost", password: "abc123" }
+    userCredentials = { username: "user", password: "abc123" }
 
     signInResponse =
       success: true
       auth_token: "a_fake_token"
       user:
         id: 1
-        system_role: "admin"
+        system_role: "Admin"
         first_name: "Test"
         last_name: "User"
         nickname: "anon"


    expect(currentUser).toEqual defaultAnonymousUser
    httpBackend.expectPOST(authenticationUrl).respond(signInResponse)
    auth.signIn authenticationUrl, { email: "user@localhost", password: "abc123" }
    httpBackend.flush()
    expect(currentUser).toEqual defaultAnonymousUser # user should not change

  it "should authorise user roles correctly", ->
    roleWhitelist = [ "basic", "admin" ]
    expect(auth.isAuthorised(roleWhitelist, "anon")).toBe(false)
    expect(auth.isAuthorised(roleWhitelist, "basic")).toBe(true)
    expect(auth.isAuthorised(roleWhitelist, "admin")).toBe(true)

    roleWhitelist = [ "admin" ]
    expect(auth.isAuthorised(roleWhitelist, "anon")).toBe(false)
    expect(auth.isAuthorised(roleWhitelist, "basic")).toBe(false)
    expect(auth.isAuthorised(roleWhitelist, "admin")).toBe(true)

    # An empty whitelist should not authorise anyone.
    roleWhitelist = []
    expect(auth.isAuthorised(roleWhitelist, "anon")).toBe(false)
    expect(auth.isAuthorised(roleWhitelist, "basic")).toBe(false)
    expect(auth.isAuthorised(roleWhitelist, "admin")).toBe(false)

    # If no whitelist is specified, anyone should be authorised.
    roleWhitelist = undefined
    expect(auth.isAuthorised(roleWhitelist, "anon")).toBe(true)
    expect(auth.isAuthorised(roleWhitelist, "basic")).toBe(true)
    expect(auth.isAuthorised(roleWhitelist, "admin")).toBe(true)

  it "should automatically intercept unauthorised API responses", ->
    intercepted = false

      auth_token: "a_fake_token"
      user:
        id: 1
        system_role: "Admin"
        first_name: "Test"
        last_name: "User"
        nickname: "anon"

    httpBackend.expectPOST(authenticationUrl).respond(signInResponse)
    auth.signIn authenticationUrl, { username: "user", password: "abc123" }
    httpBackend.flush()

    # After sign in: the current user's auth token should be present in API request params.
