Skip to content

Instantly share code, notes, and snippets.

@HonzaMac
Created December 26, 2021 20:59
Show Gist options
  • Save HonzaMac/a977435848714be3f340c1eb55f8ae8f to your computer and use it in GitHub Desktop.
Save HonzaMac/a977435848714be3f340c1eb55f8ae8f to your computer and use it in GitHub Desktop.
initial test case prior optimization
import { updateUser } from "./userService"
describe('UserService - updateUser', () => {
it('should update department', () => {
// GIVEN
const user = {
id: 'e2f5a82a-3f2e-4b6d-b4d2-086afaa08f8a',
username: 'john',
email: '[email protected]',
country: 'France',
department: 'IT Services',
divisionName: 'IT',
}
const updateData = {
department: 'IT Support',
}
// WHEN
const currentUser = updateUser(user, updateData)
// THEN
expect(currentUser).toStrictEqual({
id: 'e2f5a82a-3f2e-4b6d-b4d2-086afaa08f8a',
username: 'john',
email: '[email protected]',
country: 'France',
department: 'IT Support',
divisionName: 'IT',
})
})
it.todo('should not update on empty update');
it.todo('should update divisionName');
})
export interface User {
username: string;
email: string;
country: string;
department: string;
divisionName: string;
city?: string;
}
export const updateUser = (user: User, updateData: Partial<User>): User => ({
...user,
...updateData,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment