-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9ccb81
commit d0d72fd
Showing
1 changed file
with
141 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,160 +184,178 @@ describe('user queries', () => { | |
}) | ||
|
||
describe('user writes', () => { | ||
let oldAuthProvider = process.env.AUTH_PROVIDER | ||
|
||
afterEach(() => { | ||
process.env.AUTH_PROVIDER = oldAuthProvider | ||
Object.values(mockPassageUser).forEach((mock) => mock.mockReset()); | ||
jest.clearAllMocks(); | ||
}) | ||
|
||
scenario('creates a user <local auth>', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
describe('<Local Auth>', () => { | ||
beforeAll(() => { | ||
process.env.AUTH_PROVIDER = 'local'; | ||
}) | ||
|
||
const result = await createUser({ | ||
input: { | ||
email: '[email protected]', | ||
name: 'String', | ||
agencyId: scenario.agency.one.id, | ||
role: 'USDR_ADMIN', | ||
}, | ||
}) | ||
scenario('creates a user', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
|
||
expect(result.email).toEqual('[email protected]') | ||
}) | ||
const result = await createUser({ | ||
input: { | ||
email: '[email protected]', | ||
name: 'String', | ||
agencyId: scenario.agency.one.id, | ||
role: 'USDR_ADMIN', | ||
}, | ||
}) | ||
|
||
scenario('creates a user <passage auth>', async (scenario: StandardScenario) => { | ||
process.env.AUTH_PROVIDER = 'passage'; | ||
expect(result.email).toEqual('[email protected]') | ||
}) | ||
|
||
const passageUser = { id: 'new-id-1' }; | ||
mockPassageUser.create.mockReturnValue(passageUser) | ||
mockPassageUser.activate.mockReturnValue(passageUser); | ||
scenario('updates a user', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const email = '[email protected]' | ||
const name = 'FDR' | ||
const role = 'ORGANIZATION_STAFF' | ||
const isActive = false | ||
const original = (await user({ id: scenario.user.one.id })) as User | ||
const result = await updateUser({ | ||
id: original.id, | ||
input: { email, name, role, agencyId: scenario.agency.one.id, isActive }, | ||
}) | ||
|
||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
expect(result.email).toEqual(email) | ||
expect(result.name).toEqual(name) | ||
expect(result.role).toEqual(ROLES.ORGANIZATION_STAFF) | ||
expect(result.agencyId).toEqual(scenario.agency.one.id) | ||
expect(result.isActive).toEqual(false); | ||
}) | ||
|
||
const result = await createUser({ | ||
input: { | ||
email: '[email protected]', | ||
name: 'String', | ||
agencyId: scenario.agency.one.id, | ||
role: 'USDR_ADMIN', | ||
}, | ||
scenario('deletes a user', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const original = (await deleteUser({ | ||
id: scenario.user.one.id, | ||
})) as User | ||
const result = await user({ id: original.id }) | ||
|
||
expect(result).toEqual(null) | ||
expect(mockPassageUser.delete).not.toHaveBeenCalled(); | ||
}) | ||
|
||
expect(result.passageId).toEqual('new-id-1'); | ||
}) | ||
scenario('deletes a user', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const original = (await deleteUser({ | ||
id: scenario.user.one.id, | ||
})) as User | ||
const result = await user({ id: original.id }) | ||
|
||
scenario('updates a user <local auth>', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const email = '[email protected]' | ||
const name = 'FDR' | ||
const role = 'ORGANIZATION_STAFF' | ||
const isActive = false | ||
const original = (await user({ id: scenario.user.one.id })) as User | ||
const result = await updateUser({ | ||
id: original.id, | ||
input: { email, name, role, agencyId: scenario.agency.one.id, isActive }, | ||
expect(result).toEqual(null) | ||
expect(mockPassageUser.delete).not.toHaveBeenCalled(); | ||
}) | ||
|
||
expect(result.email).toEqual(email) | ||
expect(result.name).toEqual(name) | ||
expect(result.role).toEqual(ROLES.ORGANIZATION_STAFF) | ||
expect(result.agencyId).toEqual(scenario.agency.one.id) | ||
expect(result.isActive).toEqual(false); | ||
}) | ||
|
||
scenario('updates a user <passage auth> - deactivate', async (scenario: StandardScenario) => { | ||
process.env.AUTH_PROVIDER = 'passage'; | ||
|
||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const email = '[email protected]' | ||
const name = 'FDR' | ||
const role = 'ORGANIZATION_STAFF' | ||
const isActive = false | ||
const original = (await user({ id: scenario.user.one.id })) as User | ||
const result = await updateUser({ | ||
id: original.id, | ||
input: { email, name, role, agencyId: scenario.agency.one.id, isActive }, | ||
describe('<Passage Auth>', () => { | ||
beforeAll(() => { | ||
process.env.AUTH_PROVIDER = 'passage'; | ||
process.env.PASSAGE_API_KEY = 'fake_api_key' | ||
process.env.PASSAGE_APP_ID = 'fake_app_id' | ||
}) | ||
|
||
expect(result.isActive).toEqual(false); | ||
expect(result.passageId).toEqual(null); | ||
expect(mockPassageUser.delete).toHaveBeenCalledWith(original.passageId); | ||
}) | ||
scenario('creates a user', async (scenario: StandardScenario) => { | ||
const passageUser = { id: 'new-id-1' }; | ||
mockPassageUser.create.mockReturnValue(passageUser) | ||
mockPassageUser.activate.mockReturnValue(passageUser); | ||
|
||
scenario('updates a user <passage auth> - activate', async (scenario: StandardScenario) => { | ||
process.env.AUTH_PROVIDER = 'passage'; | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
|
||
const passageUser = { id: 'new-id-1' }; | ||
mockPassageUser.create.mockReturnValue(passageUser) | ||
mockPassageUser.activate.mockReturnValue(passageUser); | ||
const result = await createUser({ | ||
input: { | ||
email: '[email protected]', | ||
name: 'String', | ||
agencyId: scenario.agency.one.id, | ||
role: 'USDR_ADMIN', | ||
}, | ||
}) | ||
|
||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const original = (await user({ id: scenario.user.inactive.id })) as User | ||
const result = await updateUser({ | ||
id: original.id, | ||
input: { | ||
email: original.email, | ||
name: original.name, | ||
role: original.role, | ||
agencyId: original.agencyId, | ||
isActive: true | ||
}, | ||
expect(result.passageId).toEqual('new-id-1'); | ||
}) | ||
|
||
expect(result.isActive).toEqual(true); | ||
expect(result.passageId).toEqual('new-id-1'); | ||
expect(mockPassageUser.create).toHaveBeenCalledWith({ email: original.email }); | ||
}) | ||
scenario('updates a user - deactivate', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const email = '[email protected]' | ||
const name = 'FDR' | ||
const role = 'ORGANIZATION_STAFF' | ||
const isActive = false | ||
const original = (await user({ id: scenario.user.one.id })) as User | ||
const result = await updateUser({ | ||
id: original.id, | ||
input: { email, name, role, agencyId: scenario.agency.one.id, isActive }, | ||
}) | ||
|
||
scenario('deletes a user <local auth>', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
expect(result.isActive).toEqual(false); | ||
expect(result.passageId).toEqual(null); | ||
expect(mockPassageUser.delete).toHaveBeenCalledWith(original.passageId); | ||
}) | ||
const original = (await deleteUser({ | ||
id: scenario.user.one.id, | ||
})) as User | ||
const result = await user({ id: original.id }) | ||
|
||
expect(result).toEqual(null) | ||
expect(mockPassageUser.delete).not.toHaveBeenCalled(); | ||
}) | ||
scenario('updates a user - activate', async (scenario: StandardScenario) => { | ||
const passageUser = { id: 'new-id-1' }; | ||
mockPassageUser.create.mockReturnValue(passageUser) | ||
mockPassageUser.activate.mockReturnValue(passageUser); | ||
|
||
scenario('deletes a user <passage auth>', async (scenario: StandardScenario) => { | ||
process.env.AUTH_PROVIDER = 'passage'; | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const original = (await user({ id: scenario.user.inactive.id })) as User | ||
const result = await updateUser({ | ||
id: original.id, | ||
input: { | ||
email: original.email, | ||
name: original.name, | ||
role: original.role, | ||
agencyId: original.agencyId, | ||
isActive: true | ||
}, | ||
}) | ||
|
||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
expect(result.isActive).toEqual(true); | ||
expect(result.passageId).toEqual('new-id-1'); | ||
expect(mockPassageUser.create).toHaveBeenCalledWith({ email: original.email }); | ||
}) | ||
const original = (await deleteUser({ | ||
id: scenario.user.one.id, | ||
})) as User | ||
|
||
expect(mockPassageUser.delete).toHaveBeenCalledWith(original.passageId); | ||
scenario('deletes a user', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
const original = (await deleteUser({ | ||
id: scenario.user.one.id, | ||
})) as User | ||
|
||
expect(mockPassageUser.delete).toHaveBeenCalledWith(original.passageId); | ||
}) | ||
}) | ||
}) | ||
|
||
|