|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | +/// <reference types="cypress" /> |
| 3 | + |
| 4 | +describe('Test 11: Webhooks CRUD Operations', () => { |
| 5 | + const webhookTitle = 'Test Webhook ' + Date.now() |
| 6 | + const webhookUrl = 'https://webhook.site/' + Date.now() |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + cy.clearCookies() |
| 10 | + }) |
| 11 | + |
| 12 | + it('should allow admin to access webhooks page', () => { |
| 13 | + // Step 1: Login as admin |
| 14 | + cy.loginAsAdmin() |
| 15 | + |
| 16 | + // Step 2: Navigate to webhooks page |
| 17 | + cy.visit('/admin/webhooks') |
| 18 | + cy.url({ timeout: 10000 }).should('include', '/admin/webhooks') |
| 19 | + |
| 20 | + // Step 3: Verify page elements |
| 21 | + cy.contains('Webhooks', { timeout: 10000 }).should('be.visible') |
| 22 | + cy.contains('button', 'New webhook').should('be.visible') |
| 23 | + }) |
| 24 | + |
| 25 | + it('should create a new webhook', () => { |
| 26 | + // Step 1: Login and navigate to webhooks |
| 27 | + cy.loginAsAdmin() |
| 28 | + cy.visit('/admin/webhooks') |
| 29 | + |
| 30 | + // Step 2: Click create webhook button |
| 31 | + cy.contains('button', 'New webhook').click() |
| 32 | + |
| 33 | + // Step 3: Should navigate to new webhook form |
| 34 | + cy.url({ timeout: 10000 }).should('include', '/admin/webhooks/new') |
| 35 | + cy.contains('New webhook', { timeout: 10000 }).should('be.visible') |
| 36 | + |
| 37 | + // Step 4: Fill in webhook form (using Input components with v-model) |
| 38 | + cy.get('input[type="text"]').first().type(webhookTitle) |
| 39 | + cy.get('input[type="url"]').type(webhookUrl) |
| 40 | + cy.get('input[type="text"]').eq(1).type('test_webhook_secret_123') |
| 41 | + |
| 42 | + // Step 5: Select event types (checkboxes) |
| 43 | + cy.get('input[type="checkbox"]').then(($checkboxes) => { |
| 44 | + // Select first 3 event types |
| 45 | + cy.wrap($checkboxes[0]).check() |
| 46 | + cy.wrap($checkboxes[1]).check() |
| 47 | + cy.wrap($checkboxes[2]).check() |
| 48 | + }) |
| 49 | + |
| 50 | + // Step 6: Add description (optional) |
| 51 | + cy.get('textarea').type('E2E test webhook for document and signature events') |
| 52 | + |
| 53 | + // Step 7: Submit form |
| 54 | + cy.get('button[type="submit"]').click() |
| 55 | + |
| 56 | + // Step 8: Should redirect back to webhooks list |
| 57 | + cy.url({ timeout: 10000 }).should('eq', Cypress.config('baseUrl') + '/admin/webhooks') |
| 58 | + |
| 59 | + // Step 9: Verify webhook appears in list |
| 60 | + cy.contains(webhookTitle, { timeout: 10000 }).should('be.visible') |
| 61 | + cy.contains(webhookUrl).should('be.visible') |
| 62 | + |
| 63 | + // Step 10: Verify webhook is active (check for "Active" status) |
| 64 | + cy.contains('table tbody tr', webhookTitle).within(() => { |
| 65 | + cy.contains('Active').should('be.visible') |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + it('should edit webhook', () => { |
| 70 | + // Step 1: Login and navigate to webhooks |
| 71 | + cy.loginAsAdmin() |
| 72 | + cy.visit('/admin/webhooks') |
| 73 | + |
| 74 | + // Step 2: Click Edit button on webhook row |
| 75 | + cy.contains('table tbody tr', webhookTitle, { timeout: 10000 }).within(() => { |
| 76 | + cy.contains('button', 'Edit').click() |
| 77 | + }) |
| 78 | + |
| 79 | + // Step 3: Should navigate to webhook edit page |
| 80 | + cy.url({ timeout: 10000 }).should('include', '/admin/webhooks/') |
| 81 | + cy.contains('Edit webhook', { timeout: 10000 }).should('be.visible') |
| 82 | + |
| 83 | + // Step 4: Verify webhook data is loaded |
| 84 | + cy.get('input[type="text"]').first().should('have.value', webhookTitle) |
| 85 | + cy.get('input[type="url"]').should('have.value', webhookUrl) |
| 86 | + |
| 87 | + // Step 5: Update webhook title |
| 88 | + const updatedTitle = webhookTitle + ' (Updated)' |
| 89 | + cy.get('input[type="text"]').first().clear().type(updatedTitle) |
| 90 | + |
| 91 | + // Step 6: Update description |
| 92 | + cy.get('textarea').clear().type('Updated webhook description') |
| 93 | + |
| 94 | + // Step 7: Submit form |
| 95 | + cy.get('button[type="submit"]').click() |
| 96 | + |
| 97 | + // Step 8: Should redirect back to webhooks list |
| 98 | + cy.url({ timeout: 10000 }).should('eq', Cypress.config('baseUrl') + '/admin/webhooks') |
| 99 | + |
| 100 | + // Step 9: Verify updated title appears in list |
| 101 | + cy.contains(updatedTitle, { timeout: 10000 }).should('be.visible') |
| 102 | + }) |
| 103 | + |
| 104 | + it('should disable webhook', () => { |
| 105 | + // Step 1: Login and navigate to webhooks |
| 106 | + cy.loginAsAdmin() |
| 107 | + cy.visit('/admin/webhooks') |
| 108 | + |
| 109 | + // Step 2: Find webhook row and disable it |
| 110 | + const updatedTitle = webhookTitle + ' (Updated)' |
| 111 | + cy.contains('table tbody tr', updatedTitle, { timeout: 10000 }).within(() => { |
| 112 | + cy.contains('button', 'Disable').click() |
| 113 | + }) |
| 114 | + |
| 115 | + // Step 3: Verify webhook is now inactive |
| 116 | + cy.contains('table tbody tr', updatedTitle, { timeout: 10000 }).within(() => { |
| 117 | + cy.contains('Inactive').should('be.visible') |
| 118 | + }) |
| 119 | + }) |
| 120 | + |
| 121 | + it('should enable webhook', () => { |
| 122 | + // Step 1: Login and navigate to webhooks |
| 123 | + cy.loginAsAdmin() |
| 124 | + cy.visit('/admin/webhooks') |
| 125 | + |
| 126 | + // Step 2: Find webhook row and enable it |
| 127 | + const updatedTitle = webhookTitle + ' (Updated)' |
| 128 | + cy.contains('table tbody tr', updatedTitle, { timeout: 10000 }).within(() => { |
| 129 | + cy.contains('button', 'Enable').click() |
| 130 | + }) |
| 131 | + |
| 132 | + // Step 3: Verify webhook is now active |
| 133 | + cy.contains('table tbody tr', updatedTitle, { timeout: 10000 }).within(() => { |
| 134 | + cy.contains('Active').should('be.visible') |
| 135 | + }) |
| 136 | + }) |
| 137 | + |
| 138 | + it('should delete webhook from list', () => { |
| 139 | + // Step 1: Login and navigate to webhooks |
| 140 | + cy.loginAsAdmin() |
| 141 | + cy.visit('/admin/webhooks') |
| 142 | + |
| 143 | + // Step 2: Find webhook row and click delete button |
| 144 | + const updatedTitle = webhookTitle + ' (Updated)' |
| 145 | + cy.contains('table tbody tr', updatedTitle, { timeout: 10000 }).within(() => { |
| 146 | + cy.contains('button', 'Delete').click() |
| 147 | + }) |
| 148 | + |
| 149 | + // Step 3: Confirm deletion in browser confirm dialog (handled by Cypress automatically) |
| 150 | + // The webhook list page uses native confirm() dialog |
| 151 | + |
| 152 | + // Step 4: Verify webhook is deleted from list |
| 153 | + cy.contains(updatedTitle, { timeout: 10000 }).should('not.exist') |
| 154 | + }) |
| 155 | + |
| 156 | + it('should prevent non-admin from accessing webhooks', () => { |
| 157 | + // Step 1: Login as regular user (not admin) |
| 158 | + cy.loginViaMagicLink('user@test.com') |
| 159 | + |
| 160 | + // Step 2: Try to navigate to webhooks page |
| 161 | + cy.visit('/admin/webhooks', { failOnStatusCode: false }) |
| 162 | + |
| 163 | + // Step 3: Should redirect to home |
| 164 | + cy.url({ timeout: 10000 }).should('not.include', '/admin/webhooks') |
| 165 | + cy.url().should('match', /\/$/) |
| 166 | + }) |
| 167 | +}) |
0 commit comments