2023-06-21 11:56:59 +03:00
const assert = require ( 'assert/strict' ) ;
2022-04-19 15:42:31 +03:00
const sinon = require ( 'sinon' ) ;
const APIVersionCompatibilityService = require ( '../index' ) ;
describe ( 'APIVersionCompatibilityService' , function ( ) {
2022-05-05 07:16:20 +03:00
const getSiteUrl = ( ) => 'https://amazeballsghostsite.com' ;
const getSiteTitle = ( ) => 'Tahini and chickpeas' ;
2022-05-09 13:14:41 +03:00
let UserModel ;
2022-05-10 12:33:15 +03:00
let ApiKeyModel ;
2022-05-09 13:14:41 +03:00
let settingsService ;
beforeEach ( function ( ) {
UserModel = {
findAll : sinon
. stub ( )
. withArgs ( {
withRelated : [ 'roles' ] ,
filter : 'status:active'
} , {
internal : true
} )
. resolves ( {
toJSON : ( ) => [ {
email : 'simon@example.com' ,
roles : [ {
name : 'Administrator'
} ]
} ]
} )
} ;
2022-05-10 12:33:15 +03:00
ApiKeyModel = {
findOne : sinon
. stub ( )
. withArgs ( {
secret : 'super_secret'
} , {
withRelated : [ 'integration' ]
} )
. resolves ( {
relations : {
integration : {
2023-01-30 12:57:02 +03:00
toJSON : ( ) => ( {
name : 'Elaborate Fox' ,
type : 'custom'
} )
2022-05-10 12:33:15 +03:00
}
}
} )
} ;
2022-05-09 13:14:41 +03:00
settingsService = {
read : sinon . stub ( ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [
'v3.4' ,
'v4.1'
] )
}
} ) ,
edit : sinon . stub ( ) . resolves ( )
} ;
} ) ;
2022-05-05 07:16:20 +03:00
2022-04-20 06:08:56 +03:00
afterEach ( function ( ) {
sinon . reset ( ) ;
} ) ;
2022-04-21 10:54:28 +03:00
it ( 'Sends an email to the instance owners when fresh accept-version header mismatch detected' , async function ( ) {
2022-04-19 15:42:31 +03:00
const sendEmail = sinon . spy ( ) ;
const compatibilityService = new APIVersionCompatibilityService ( {
2022-05-09 13:14:41 +03:00
UserModel ,
2022-05-10 12:33:15 +03:00
ApiKeyModel ,
2022-05-09 13:14:41 +03:00
settingsService ,
2022-04-20 06:08:56 +03:00
sendEmail ,
2022-05-05 07:16:20 +03:00
getSiteUrl ,
getSiteTitle
2022-04-19 15:42:31 +03:00
} ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
2022-05-11 05:08:32 +03:00
userAgent : 'GhostAdminSDK/2.4.0' ,
2022-05-11 05:10:45 +03:00
requestURL : '/ghost/api/admin/posts/dew023d9203se4' ,
2022-05-10 12:33:15 +03:00
apiKeyValue : 'secret' ,
apiKeyType : 'content'
2022-04-19 15:42:31 +03:00
} ) ;
assert . equal ( sendEmail . called , true ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . to , 'simon@example.com' ) ;
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . subject , ` Attention required: Your Elaborate Fox integration has failed ` ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Your <strong style="font-weight: 600;">Elaborate Fox<\/strong> integration is no longer working as expected\./ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Integration expected Ghost version:<\/strong> v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Current Ghost version:<\/strong> v5.1/ ) ;
2022-05-11 05:10:45 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Failed request URL:<\/strong> \/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /This email was sent from <a href="https:\/\/amazeballsghostsite.com"/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /to <a href="mailto:simon@example.com"/ ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Your Elaborate Fox integration is no longer working/ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Integration expected Ghost version:v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Current Ghost version:v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Failed request URL:/ ) ;
2022-05-11 05:10:45 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /This email was sent from https:\/\/amazeballsghostsite.com/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /to simon@example.com/ ) ;
2022-04-19 15:42:31 +03:00
} ) ;
2022-04-20 06:08:56 +03:00
it ( 'Does NOT send an email to the instance owner when previously handled accept-version header mismatch is detected' , async function ( ) {
const sendEmail = sinon . spy ( ) ;
2022-05-09 13:14:41 +03:00
settingsService = {
read : sinon . stub ( )
. onFirstCall ( ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [ ] )
}
} )
. onSecondCall ( ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [ ] )
}
} )
. onThirdCall ( ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [
'v4.5'
] )
}
} ) ,
edit : sinon . stub ( ) . resolves ( )
} ;
2022-04-20 06:08:56 +03:00
const compatibilityService = new APIVersionCompatibilityService ( {
sendEmail ,
2022-05-10 12:33:15 +03:00
ApiKeyModel ,
2022-05-09 13:14:41 +03:00
UserModel ,
settingsService ,
2022-05-05 07:16:20 +03:00
getSiteUrl ,
getSiteTitle
2022-04-20 06:08:56 +03:00
} ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
2022-05-11 05:08:32 +03:00
userAgent : 'GhostAdminSDK/2.4.0' ,
2022-05-10 12:33:15 +03:00
requestURL : 'https://amazeballsghostsite.com/ghost/api/admin/posts/dew023d9203se4' ,
apiKeyValue : 'secret' ,
apiKeyType : 'content'
2022-04-20 06:08:56 +03:00
} ) ;
2022-05-05 07:16:20 +03:00
assert . equal ( sendEmail . called , true ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . to , 'simon@example.com' ) ;
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . subject , ` Attention required: Your Elaborate Fox integration has failed ` ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Your <strong style="font-weight: 600;">Elaborate Fox<\/strong> integration is no longer working as expected\./ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Integration expected Ghost version:<\/strong> v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Current Ghost version:<\/strong> v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Failed request URL:<\/strong> https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /This email was sent from <a href="https:\/\/amazeballsghostsite.com"/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /to <a href="mailto:simon@example.com"/ ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Your Elaborate Fox integration is no longer working/ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Integration expected Ghost version:v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Current Ghost version:v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Failed request URL:/ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /This email was sent from https:\/\/amazeballsghostsite.com/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /to simon@example.com/ ) ;
2022-04-20 06:08:56 +03:00
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
2022-05-11 05:08:32 +03:00
userAgent : 'GhostAdminSDK/2.4.0' ,
2022-05-10 12:33:15 +03:00
requestURL : 'does not matter' ,
apiKeyValue : 'secret' ,
apiKeyType : 'content'
2022-04-20 06:08:56 +03:00
} ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . calledOnce , true ) ;
2022-04-20 06:08:56 +03:00
assert . equal ( sendEmail . calledTwice , false ) ;
} ) ;
2024-05-02 13:51:27 +03:00
it ( 'Does not send email when unknown integration is detected' , async function ( ) {
const sendEmail = sinon . spy ( ) ;
const findOneStub = sinon . stub ( ) ;
findOneStub
. withArgs ( {
id : 'unknown_key'
} , {
withRelated : [ 'integration' ]
} )
. resolves ( null ) ;
ApiKeyModel = {
findOne : findOneStub
} ;
const compatibilityService = new APIVersionCompatibilityService ( {
sendEmail ,
ApiKeyModel ,
UserModel ,
settingsService ,
getSiteUrl ,
getSiteTitle
} ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
userAgent : 'GhostAdminSDK/2.4.0' ,
requestURL : 'https://amazeballsghostsite.com/ghost/api/admin/posts/dew023d9203se4' ,
apiKeyValue : 'unknown_key' ,
apiKeyType : 'content'
} ) ;
assert . equal ( sendEmail . called , false ) ;
} ) ;
2023-01-30 12:57:02 +03:00
it ( 'Does NOT send an email to the instance owner when "internal" or "core" integration triggered version mismatch' , async function ( ) {
const sendEmail = sinon . spy ( ) ;
const findOneStub = sinon . stub ( ) ;
findOneStub
. withArgs ( {
id : 'secret_core'
} , {
withRelated : [ 'integration' ]
} )
. resolves ( {
relations : {
integration : {
toJSON : ( ) => ( {
name : 'Core Integration' ,
type : 'core'
} )
}
}
} ) ;
findOneStub
. withArgs ( {
id : 'secrete_internal'
} , {
withRelated : [ 'integration' ]
} )
. resolves ( {
relations : {
integration : {
toJSON : ( ) => ( {
name : 'Internal Integration' ,
type : 'internal'
} )
}
}
} ) ;
findOneStub
. withArgs ( {
secret : 'custom_key_id'
} , {
withRelated : [ 'integration' ]
} )
. resolves ( {
relations : {
integration : {
toJSON : ( ) => ( {
name : 'Custom Integration' ,
type : 'custom'
} )
}
}
} ) ;
ApiKeyModel = {
findOne : findOneStub
} ;
settingsService = {
read : sinon . stub ( ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [ ] )
}
} ) ,
edit : sinon . stub ( ) . resolves ( )
} ;
const compatibilityService = new APIVersionCompatibilityService ( {
sendEmail ,
ApiKeyModel ,
UserModel ,
settingsService ,
getSiteUrl ,
getSiteTitle
} ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
userAgent : 'GhostAdminSDK/2.4.0' ,
requestURL : '' ,
apiKeyValue : 'secret_core' ,
apiKeyType : 'admin'
} ) ;
assert . equal ( sendEmail . called , false ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
userAgent : 'GhostAdminSDK/2.4.0' ,
requestURL : 'does not matter' ,
apiKeyValue : 'secrete_internal' ,
apiKeyType : 'admin'
} ) ;
assert . equal ( sendEmail . called , false ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
userAgent : 'GhostContentSDK/2.4.0' ,
requestURL : 'https://amazeballsghostsite.com/ghost/api/admin/posts/dew023d9203se4' ,
apiKeyValue : 'custom_key_id' ,
apiKeyType : 'content'
} ) ;
assert . equal ( sendEmail . called , true ) ;
} ) ;
2022-04-21 10:54:28 +03:00
it ( 'Does send multiple emails to the instance owners when previously unhandled accept-version header mismatch is detected' , async function ( ) {
2022-04-20 06:08:56 +03:00
const sendEmail = sinon . spy ( ) ;
2022-05-09 13:14:41 +03:00
UserModel = {
findAll : sinon
. stub ( )
. withArgs ( {
withRelated : [ 'roles' ] ,
filter : 'status:active'
} , {
internal : true
} )
. resolves ( {
toJSON : ( ) => [ {
email : 'simon@example.com' ,
roles : [ {
name : 'Administrator'
} ]
} , {
email : 'sam@example.com' ,
roles : [ {
name : 'Owner'
} ]
} ]
} )
} ;
settingsService = {
read : sinon . stub ( )
. onCall ( 0 ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [ ] )
}
} )
. onCall ( 1 ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [ ] )
}
} )
. onCall ( 2 ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [
'v4.5'
] )
}
} )
. onCall ( 3 ) . resolves ( {
version _notifications : {
value : JSON . stringify ( [
'v4.5'
] )
}
} ) ,
edit : sinon . stub ( ) . resolves ( )
} ;
2022-04-20 06:08:56 +03:00
const compatibilityService = new APIVersionCompatibilityService ( {
sendEmail ,
2022-05-09 13:14:41 +03:00
UserModel ,
2022-05-10 12:33:15 +03:00
ApiKeyModel ,
2022-05-09 13:14:41 +03:00
settingsService ,
2022-05-05 07:16:20 +03:00
getSiteUrl ,
getSiteTitle
2022-04-20 06:08:56 +03:00
} ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
2022-05-11 05:08:32 +03:00
userAgent : 'GhostAdminSDK/2.4.0' ,
2022-05-10 12:33:15 +03:00
requestURL : 'https://amazeballsghostsite.com/ghost/api/admin/posts/dew023d9203se4' ,
apiKeyValue : 'secret' ,
apiKeyType : 'content'
2022-04-20 06:08:56 +03:00
} ) ;
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . calledTwice , true ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . to , 'simon@example.com' ) ;
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . subject , ` Attention required: Your Elaborate Fox integration has failed ` ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Your <strong style="font-weight: 600;">Elaborate Fox<\/strong> integration is no longer working as expected\./ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Integration expected Ghost version:<\/strong> v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Current Ghost version:<\/strong> v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /Failed request URL:<\/strong> https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /This email was sent from <a href="https:\/\/amazeballsghostsite.com"/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /to <a href="mailto:simon@example.com"/ ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Your Elaborate Fox integration is no longer working/ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Integration expected Ghost version:v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Current Ghost version:v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /Failed request URL:/ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /This email was sent from https:\/\/amazeballsghostsite.com/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /to simon@example.com/ ) ;
2022-04-20 06:08:56 +03:00
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . calledTwice , true ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . args [ 1 ] [ 0 ] . to , 'sam@example.com' ) ;
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . args [ 1 ] [ 0 ] . subject , ` Attention required: Your Elaborate Fox integration has failed ` ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . html , /Your <strong style="font-weight: 600;">Elaborate Fox<\/strong> integration is no longer working as expected\./ ) ;
assert . match ( sendEmail . args [ 1 ] [ 0 ] . html , /Integration expected Ghost version:<\/strong> v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . html , /Current Ghost version:<\/strong> v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . html , /Failed request URL:<\/strong> https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . html , /This email was sent from <a href="https:\/\/amazeballsghostsite.com"/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . html , /to <a href="mailto:sam@example.com"/ ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /Your Elaborate Fox integration is no longer working/ ) ;
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /Integration expected Ghost version:v4.5/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /Current Ghost version:v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /Failed request URL:/ ) ;
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /This email was sent from https:\/\/amazeballsghostsite.com/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 1 ] [ 0 ] . text , /to sam@example.com/ ) ;
2022-04-21 10:54:28 +03:00
2022-04-20 06:08:56 +03:00
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.8' ,
contentVersion : 'v5.1' ,
2022-05-11 05:08:32 +03:00
userAgent : 'GhostAdminSDK/2.4.0' ,
2022-05-10 12:33:15 +03:00
requestURL : 'https://amazeballsghostsite.com/ghost/api/admin/posts/dew023d9203se4' ,
apiKeyValue : 'secret' ,
apiKeyType : 'content'
2022-04-20 06:08:56 +03:00
} ) ;
2022-04-21 10:54:28 +03:00
assert . equal ( sendEmail . callCount , 4 ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . args [ 2 ] [ 0 ] . to , 'simon@example.com' ) ;
2022-05-05 07:16:20 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 2 ] [ 0 ] . html , /Your <strong style="font-weight: 600;">Elaborate Fox<\/strong> integration is no longer working as expected\./ ) ;
assert . match ( sendEmail . args [ 2 ] [ 0 ] . html , /Integration expected Ghost version:<\/strong> v4.8/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 2 ] [ 0 ] . html , /Current Ghost version:<\/strong> v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 2 ] [ 0 ] . html , /Failed request URL:<\/strong> https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 2 ] [ 0 ] . text , /Your Elaborate Fox integration is no longer working/ ) ;
assert . match ( sendEmail . args [ 2 ] [ 0 ] . text , /Integration expected Ghost version:v4.8/ ) ;
2022-05-05 07:16:20 +03:00
assert . match ( sendEmail . args [ 2 ] [ 0 ] . text , /Current Ghost version:v5.1/ ) ;
2022-05-05 09:51:47 +03:00
assert . match ( sendEmail . args [ 2 ] [ 0 ] . text , /Failed request URL:/ ) ;
assert . match ( sendEmail . args [ 2 ] [ 0 ] . text , /https:\/\/amazeballsghostsite.com\/ghost\/api\/admin\/posts\/dew023d9203se4/ ) ;
2022-04-20 06:08:56 +03:00
} ) ;
2022-05-04 06:05:48 +03:00
2022-05-05 07:43:55 +03:00
it ( 'Sends Zapier-specific email when userAgent is a Zapier client' , async function ( ) {
const sendEmail = sinon . spy ( ) ;
const compatibilityService = new APIVersionCompatibilityService ( {
sendEmail ,
2022-05-09 13:14:41 +03:00
UserModel ,
2022-05-10 12:33:15 +03:00
ApiKeyModel ,
2022-05-09 13:14:41 +03:00
settingsService ,
2022-05-05 07:43:55 +03:00
getSiteUrl ,
getSiteTitle
} ) ;
await compatibilityService . handleMismatch ( {
acceptVersion : 'v4.5' ,
contentVersion : 'v5.1' ,
2022-05-05 09:51:47 +03:00
userAgent : 'Zapier/4.20 GhostAdminSDK/2.4.0' ,
2022-05-10 12:33:15 +03:00
requestURL : 'https://amazeballsghostsite.com/ghost/api/admin/posts/dew023d9203se4' ,
apiKeyValue : 'secret' ,
apiKeyType : 'content'
2022-05-05 07:43:55 +03:00
} ) ;
assert . equal ( sendEmail . called , true ) ;
2022-05-09 13:14:41 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . to , 'simon@example.com' ) ;
2022-05-05 07:43:55 +03:00
assert . equal ( sendEmail . args [ 0 ] [ 0 ] . subject , ` Attention required: One of your Zaps has failed ` ) ;
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /One of the Zaps in your Zapier integration has <span style="font-weight: 600;">stopped working<\/span>\./ ) ;
2022-05-05 07:43:55 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /To get this resolved as quickly as possible, please log in to your Zapier account to view any failing Zaps and recreate them using the most recent Ghost-supported versions. Zap errors can be found <a href="https:\/\/zapier.com\/app\/history\/usage" style="color: #738A94;">here<\/a> in your “Zap history”\./ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /This email was sent from <a href="https:\/\/amazeballsghostsite.com"/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . html , /to <a href="mailto:simon@example.com"/ ) ;
2022-05-05 07:43:55 +03:00
2022-05-11 05:48:32 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /One of the Zaps in your Zapier integration has stopped/ ) ;
2022-05-05 07:43:55 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /To get this resolved as quickly as possible, please log in to your Zapier/ ) ;
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /This email was sent from https:\/\/amazeballsghostsite.com/ ) ;
2022-05-09 13:14:41 +03:00
assert . match ( sendEmail . args [ 0 ] [ 0 ] . text , /to simon@example.com/ ) ;
2022-05-05 07:43:55 +03:00
} ) ;
2022-04-19 15:42:31 +03:00
} ) ;