Skip to content

Instantly share code, notes, and snippets.

@jonurry
Created April 29, 2020 15:58
Show Gist options
  • Save jonurry/bd929451008da9a3a6183b9eaeea0d48 to your computer and use it in GitHub Desktop.
Save jonurry/bd929451008da9a3a6183b9eaeea0d48 to your computer and use it in GitHub Desktop.
const {
copyAllProjectCustomFields,
} = require('./copy_all_project_custom_fields');
const { falafel } = require('./mocks');
const input = {
access_token: 1234,
destination_project_id: 2,
source_project_id: 1,
};
describe('copy all project custom fields', () => {
beforeEach(() => {
jest.clearAllMocks();
});
test('getProject is called once with correct input', async () => {
await copyAllProjectCustomFields(input);
expect(falafel.asana.getProject).toHaveBeenCalledTimes(1);
expect(falafel.asana.getProject).toHaveBeenCalledWith({
access_token: input.access_token,
project_id: input.source_project_id,
});
});
test('addCustomFieldToProject is called twice with correct input', async () => {
await copyAllProjectCustomFields(input);
expect(falafel.asana.addCustomFieldToProject).toHaveBeenCalledTimes(2);
expect(falafel.asana.addCustomFieldToProject).toHaveBeenNthCalledWith(
1,
{
access_token: input.access_token,
project_id: input.destination_project_id,
custom_field_id: '1',
is_important: true,
},
);
expect(falafel.asana.addCustomFieldToProject).toHaveBeenNthCalledWith(
2,
{
access_token: input.access_token,
project_id: input.destination_project_id,
custom_field_id: '2',
is_important: false,
},
);
});
test('returns success and number of fields added', async () => {
const result = await copyAllProjectCustomFields(input);
expect(result).toEqual({ success: true, fieldsCopied: 2 });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment