Skip to content

Commit

Permalink
reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-adams committed Aug 28, 2024
1 parent b9ccb81 commit d0d72fd
Showing 1 changed file with 141 additions and 123 deletions.
264 changes: 141 additions & 123 deletions api/src/services/users/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check warning on line 188 in api/src/services/users/users.test.ts

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Delete `;`
})

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';

Check warning on line 193 in api/src/services/users/users.test.ts

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Delete `;`
})

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);
})
})
})

Expand Down

0 comments on commit d0d72fd

Please sign in to comment.