diff --git a/tests/integration/targets/discord/README.md b/tests/integration/targets/discord/README.md new file mode 100644 index 0000000000..0cd3277924 --- /dev/null +++ b/tests/integration/targets/discord/README.md @@ -0,0 +1,14 @@ +The integration tests can be executed locally: + +1. Create or use an existing discord server +2. Open `Server Settings` and navigate to `Integrations` tab +3. Click `Create Webhook` to create a new webhook +4. Click `Copy Webhook URL` and extract the webhook_id + webhook_token + + Example: https://discord.com/api/webhooks/`webhook_id`/`webhook_token` + +5. Replace the variables `discord_id` and `discord_token` in the var file +6. Run the integration test +```` +ansible-test integration -v --color yes discord --allow-unsupported +```` diff --git a/tests/integration/targets/discord/aliases b/tests/integration/targets/discord/aliases new file mode 100644 index 0000000000..ad7ccf7ada --- /dev/null +++ b/tests/integration/targets/discord/aliases @@ -0,0 +1 @@ +unsupported diff --git a/tests/integration/targets/discord/defaults/main.yml b/tests/integration/targets/discord/defaults/main.yml new file mode 100644 index 0000000000..bf2b818178 --- /dev/null +++ b/tests/integration/targets/discord/defaults/main.yml @@ -0,0 +1,2 @@ +discord_id: 000 +discord_token: xxx diff --git a/tests/integration/targets/discord/tasks/main.yml b/tests/integration/targets/discord/tasks/main.yml new file mode 100644 index 0000000000..44cd663756 --- /dev/null +++ b/tests/integration/targets/discord/tasks/main.yml @@ -0,0 +1,64 @@ +#################################################################### +# WARNING: These are designed specifically for Ansible tests # +# and should not be used as examples of how to write Ansible roles # +#################################################################### + +- name: Send basic message + community.general.discord: + webhook_id: "{{ discord_id }}" + webhook_token: "{{ discord_token }}" + content: "Messages from ansible-test" + register: result + +- name: Check result + assert: + that: + - result is changed + - result.http_code == 204 + +- name: Send embeds + community.general.discord: + webhook_id: "{{ discord_id }}" + webhook_token: "{{ discord_token }}" + embeds: + - title: "Title of embed message 1" + description: "Description embed message 1" + footer: + text: "author ansible-test" + image: + url: "https://avatars.githubusercontent.com/u/44586252?s=200&v=4" + - title: "Title of embed message 2" + description: "Description embed message 2" + footer: + text: "author ansible-test" + icon_url: "https://avatars.githubusercontent.com/u/44586252?s=200&v=4" + fields: + - name: "Field 1" + value: 1 + - name: "Field 2" + value: "Text" + timestamp: "{{ ansible_date_time.iso8601 }}" + username: Ansible Test + avatar_url: "https://avatars.githubusercontent.com/u/44586252?s=200&v=4" + register: result + +- name: Check result + assert: + that: + - result is changed + - result.http_code == 204 + +- name: Use a wrong token + community.general.discord: + webhook_id: "{{ discord_id }}" + webhook_token: "wrong_token" + content: "Messages from ansible-test" + register: result + ignore_errors: true + +- name: Check result + assert: + that: + - result is not changed + - result.http_code == 401 + - result.response.message == "Invalid Webhook Token"