Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions scripts/setup-test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,20 @@ const testForms = [
button: {
text: 'Send Message'
},
confirmations: [{
type: 'message',
message: '<p>Thank you for contacting us! We\'ll respond within 24 hours.</p>'
}],
notifications: [{
name: 'Admin Notification',
to: '{admin_email}',
subject: 'New Contact Form Submission',
message: 'You have a new contact form submission from {Name:1}.'
}]
confirmations: {
conf_1: {
type: 'message',
message: '<p>Thank you for contacting us! We\'ll respond within 24 hours.</p>'
}
},
notifications: {
notif_1: {
name: 'Admin Notification',
to: '{admin_email}',
subject: 'New Contact Form Submission',
message: 'You have a new contact form submission from {Name:1}.'
}
}
},
{
title: 'Newsletter Signup (Test)',
Expand Down Expand Up @@ -193,10 +197,12 @@ const testForms = [
button: {
text: 'Subscribe'
},
confirmations: [{
type: 'message',
message: '<p>Success! Please check your email to confirm your subscription.</p>'
}]
confirmations: {
conf_1: {
type: 'message',
message: '<p>Success! Please check your email to confirm your subscription.</p>'
}
}
},
{
title: 'Multi-Page Survey (Test)',
Expand Down Expand Up @@ -263,10 +269,12 @@ const testForms = [
button: {
text: 'Submit Survey'
},
confirmations: [{
type: 'message',
message: '<p>Thank you for your feedback!</p>'
}]
confirmations: {
conf_1: {
type: 'message',
message: '<p>Thank you for your feedback!</p>'
}
}
}
];

Expand Down
11 changes: 10 additions & 1 deletion src/config/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,19 @@ export async function validateRestApiAccess(httpClient, authManager) {
{ path: '/feeds', name: 'Feeds' }
];

// Get baseURL from httpClient for OAuth signature generation
const baseURL = httpClient?.defaults?.baseURL;

if (!baseURL) {
throw new Error('httpClient baseURL is not configured');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const results = [];
for (const endpoint of endpoints) {
try {
const headers = authManager.getAuthHeaders();
// Generate proper OAuth headers with full URL for signature
const fullUrl = `${baseURL}${endpoint.path}`;
const headers = authManager.getAuthHeaders('GET', fullUrl, { per_page: 1 });
await httpClient.get(endpoint.path, {
headers,
params: { per_page: 1 }
Expand Down
11 changes: 7 additions & 4 deletions src/config/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,18 @@ export class FormsValidator extends BaseValidator {
}

if (formData.confirmations !== undefined) {
validated.confirmations = this.validateArray(formData.confirmations, 'confirmations');
validated.confirmations = validated.confirmations.map((conf, index) => {
validated.confirmations = this.validateObject(formData.confirmations, 'confirmations');
Object.entries(validated.confirmations).forEach(([key, conf]) => {
if (conf.type === 'redirect' && conf.url !== undefined) {
conf.url = this.validateURL(conf.url, `confirmations[${index}].url`);
conf.url = this.validateURL(conf.url, `confirmations.${key}.url`);
}
return conf;
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

if (formData.notifications !== undefined) {
validated.notifications = this.validateObject(formData.notifications, 'notifications');
}

if (formData.schedule_start !== undefined) {
validated.schedule_start = this.validateDate(formData.schedule_start, 'schedule_start');
}
Expand Down
11 changes: 7 additions & 4 deletions src/config/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ export class FormsValidator {
.array()
)
.field('confirmations', validate('confirmations')
.array()
.object()
.custom((confirmations) => {
if (Array.isArray(confirmations)) {
confirmations.forEach((conf, index) => {
if (confirmations && typeof confirmations === 'object') {
Object.entries(confirmations).forEach(([key, conf]) => {
if (conf.type === 'redirect' && conf.url !== undefined) {
validate(`confirmations[${index}].url`)
validate(`confirmations.${key}.url`)
.required()
.string()
.url()
Expand All @@ -104,6 +104,9 @@ export class FormsValidator {
return true;
})
)
.field('notifications', validate('notifications')
.object()
)
.field('schedule_start', validate('schedule_start')
.string()
.date()
Expand Down
1 change: 1 addition & 0 deletions src/tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class MockHttpClient {
this.requests = [];
this.responses = new Map();
this.defaultResponse = new MockResponse();
this.defaults = { baseURL: 'https://test.example.com' };
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ suite.test('Integration: Create test form', async () => {
button: {
text: 'Submit Test'
},
confirmations: [{
type: 'message',
message: 'Thank you for your test submission!'
}]
confirmations: {
conf_1: {
type: 'message',
message: 'Thank you for your test submission!'
}
}
};

const result = await client.createForm(formData);
Expand Down
20 changes: 12 additions & 8 deletions src/tests/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ suite.test('Format Validation: URLs', async () => {
await TestAssert.throwsAsync(
() => client.createForm({
title: 'Test',
confirmations: [{
type: 'redirect',
url: 'not-a-url'
}]
confirmations: {
conf_1: {
type: 'redirect',
url: 'not-a-url'
}
}
}),
'valid URL',
'Should validate URL format'
Expand All @@ -427,10 +429,12 @@ suite.test('Format Validation: URLs', async () => {

await client.createForm({
title: 'Test',
confirmations: [{
type: 'redirect',
url: 'https://example.com'
}]
confirmations: {
conf_1: {
type: 'redirect',
url: 'https://example.com'
}
}
});
});

Expand Down