import { Collaborator, App } from "../app"; import { Options, printDuration, run, step } from "../helpers"; const add = async ( integration: App, user: User, collaboratorToAdd: Collaborator, options: Options, ) => { options.log(`Adding ${collaboratorToAdd.fullName} to ${integration.name}`); const startTime = new Date().getTime(); await run( integration, user, async (page, context) => { await step( () => integration.addCollaborator(collaboratorToAdd, page, context), "Adding the user", "Added the user", options, ); await step( async () => { const collaborators = await integration.listCollaborators( page, context, ); if ( !collaborators.some( (collaborator) => collaborator.email === collaboratorToAdd.email, ) ) { throw `Collaborator ${collaboratorToAdd.fullName} wasn't added`; } }, "Verifying that the user has been registered", "Verified that the user has been registered", options, ); options.log( `Added ${collaboratorToAdd.fullName}${options.noTimer ? "" : ` - ${printDuration(new Date().getTime() - startTime)}`}`, ); }, options, ); }; export default add;