# frozen_string_literal: true module Apps module Align # - Create Align topic # - Create Align comment def login @login ||= AlignLogin.new end def self.headless_login(creator) Services::Login.login_headless(creator) # get that user's token token = Services::Login.get_logged_in_bearer_token token end def self.create_topic(creator, participant) # use in before block participant_id = ENV.fetch("#{participant}_UUID") token = login.user_token(creator) payload = { variables: { input: { title: 'topic created by automation', participantId: participant_id } }, query: 'mutation createAlignTopic($input: CreateAlignTopicMutationInput!) { createAlignTopic(input: $input) { topic { id title resolvedAt resolvedBy { id } createdAt modifiedAt deletedAt owner { id } participants { nodes { identity { id } } } } } }' } response = JSON.parse(Api::Graphql.post(token, payload).body) Capybara.current_session.cleanup! response end def self.create_comment(creator, participant_id) topic_id = create_topic(creator, participant_id)['data']['createAlignTopic']['topic']['id'] token = headless_login(creator) payload = { variables: { input: { text: 'comment created by automation', topicId: topic_id } }, query: 'mutation createAlignTopicComment( $input: CreateAlignTopicCommentMutationInput! ) { createAlignTopicComment(input: $input) { comment { id text createdAt modifiedAt deletedAt owner { id } } } }' } response = JSON.parse(Api::Graphql.post(token, payload).body) Capybara.current_session.cleanup! response end end end