Skip to content

Commit b52cd3e

Browse files
authored
Merge pull request #26 from codeccoop/feat/addons-tests
rest api add-ons test cases
2 parents 7357c8c + 924f7ae commit b52cd3e

File tree

9 files changed

+1909
-45
lines changed

9 files changed

+1909
-45
lines changed

forms-bridge/addons/brevo/class-brevo-addon.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,42 +138,22 @@ function ( $path ) {
138138
* @return array
139139
*/
140140
public function get_endpoint_schema( $endpoint, $backend, $method = null ) {
141-
$bytes = random_bytes( 16 );
142-
$bytes[6] = chr( ord( $bytes[6] ) & 0x0f | 0x40 );
143-
$bytes[8] = chr( ord( $bytes[8] ) & 0x3f | 0x80 );
144-
$uuid = vsprintf( '%s%s-%s-%s-%s-%s%s%s', str_split( bin2hex( $bytes ), 4 ) );
141+
if ( ! function_exists( 'yaml_parse' ) ) {
142+
return array();
143+
}
145144

146-
$response = wp_remote_get(
147-
self::OAS_URL,
148-
array(
149-
'headers' => array(
150-
'Accept' => 'application/json',
151-
'Host' => 'developers.brevo.com',
152-
'Referer' => 'https://developers.brevo.com/reference/get_companies',
153-
'Alt-Used' => 'developers.brevo.com',
154-
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0',
155-
'X-Requested-With' => 'XMLHttpRequest',
156-
),
157-
'cookies' => array(
158-
'anonymous_id' => $uuid,
159-
'first_referrer' => 'https://app.brevo.com/',
160-
'pscd' => 'get.brevo.com',
161-
'readme_language' => 'shell',
162-
'readme_library' => '{%22shell%22:%22curl%22}',
163-
),
164-
)
165-
);
145+
$response = wp_remote_get( self::OAS_URL );
166146

167147
if ( is_wp_error( $response ) ) {
168148
return array();
169149
}
170150

171-
$data = json_decode( $response['body'], true );
151+
$data = yaml_parse( $response['body'] );
172152
if ( ! $data ) {
173153
return array();
174154
}
175155

176-
$oa_explorer = new OpenAPI( $data['oasDefinition'] );
156+
$oa_explorer = new OpenAPI( $data );
177157

178158
$method = strtolower( $method ?? 'post' );
179159
$path = preg_replace( '/^\/v\d+/', '', $endpoint );

forms-bridge/addons/listmonk/class-listmonk-form-bridge.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ public function submit( $payload = array(), $attachments = array() ) {
3232
$error_response = $response->get_error_data()['response'] ?? null;
3333

3434
$code = $error_response['response']['code'] ?? null;
35-
if ( $code !== 409 ) {
35+
if ( 409 !== $code ) {
3636
return $response;
3737
}
3838

39-
if (
40-
! isset( $payload['email'] ) ||
41-
$this->endpoint !== '/api/subscribers'
42-
) {
39+
if ( ! isset( $payload['email'] ) || '/api/subscribers' !== $this->endpoint ) {
4340
return $response;
4441
}
4542

forms-bridge/addons/mailchimp/class-mailchimp-form-bridge.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ public function submit( $payload = array(), $attachments = array() ) {
5454
}
5555

5656
if ( 'Member Exists' === $title ) {
57-
if (
58-
! preg_match(
59-
'/(?<=lists\/).+(?=\/members)/',
60-
$this->endpoint,
61-
$matches
62-
)
63-
) {
57+
if ( ! preg_match( '/(?<=lists\/).+(?=\/members)/', $this->endpoint, $matches ) ) {
6458
return $response;
6559
}
6660

@@ -84,17 +78,15 @@ public function submit( $payload = array(), $attachments = array() ) {
8478
return $response;
8579
}
8680

87-
$member_id =
88-
$search_response['data']['exact_matches']['members'][0]['id'] ?? null;
81+
$member_id = $search_response['data']['exact_matches']['members'][0]['id'] ?? null;
8982

9083
if ( ! $member_id ) {
9184
return $response;
9285
}
9386

9487
$update_endpoint = "/3.0/lists/{$list_id}/members/{$member_id}";
95-
if (
96-
strstr( $this->endpoint, 'skip_merge_validation' ) !== false
97-
) {
88+
89+
if ( false !== strstr( $this->endpoint, 'skip_merge_validation' ) ) {
9890
$update_endpoint .= '?skip_merge_validation=true';
9991
}
10092

forms-bridge/addons/zoho/class-zoho-form-bridge.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function ( $headers, $backend ) {
7575
if ( ! $backend ) {
7676
return new WP_Error(
7777
'invalid_backend',
78-
'The bridge does not have a valid backend'
78+
'The bridge does not have a valid backend',
79+
(array) $this->data,
7980
);
8081
}
8182

forms-bridge/includes/class-form-bridge.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ public function submit( $payload = array(), $attachments = array() ) {
454454

455455
$backend = $this->backend();
456456
if ( ! $backend ) {
457-
return new WP_Error( 'invalid_bridge' );
457+
return new WP_Error(
458+
'invalid_backend',
459+
'The bridge does not have a valid backend',
460+
(array) $this->data,
461+
);
458462
}
459463

460464
$method = $this->method;

0 commit comments

Comments
 (0)