- my 1st html
-
+
+
+
+ my 1st html
%%[
/* my ampscript */
]%%
+ // my ssjs
+
-
- my 2nd html
- |
\ No newline at end of file
+ my 2nd html
+ |
+
+
diff --git a/test/resources/9999999/automation/v1/scripts/get-response.json b/test/resources/9999999/automation/v1/scripts/get-response.json
index d928b6361..b19640196 100644
--- a/test/resources/9999999/automation/v1/scripts/get-response.json
+++ b/test/resources/9999999/automation/v1/scripts/get-response.json
@@ -1,5 +1,5 @@
{
- "count": 1,
+ "count": 5,
"page": 1,
"pageSize": 500,
"items": [
@@ -8,7 +8,7 @@
"name": "testExisting_script",
"key": "testExisting_script",
"description": "",
- "script": "",
+ "script": " ",
"categoryId": 304,
"createdDate": "2022-10-20T00:41:26.163",
"modifiedDate": "2022-10-20T00:41:26.163"
@@ -22,6 +22,36 @@
"categoryId": 304,
"createdDate": "2022-10-20T00:41:26.163",
"modifiedDate": "2022-10-20T00:41:26.163"
+ },
+ {
+ "ssjsActivityId": "39f6a488-20eb-4ba0-b0b9-ampscript",
+ "name": "testExisting_script_ampscript",
+ "key": "testExisting_script_ampscript",
+ "description": "",
+ "script": "line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2\nline3",
+ "categoryId": 304,
+ "createdDate": "2022-10-20T00:41:26.163",
+ "modifiedDate": "2022-10-20T00:41:26.163"
+ },
+ {
+ "ssjsActivityId": "39f6a488-20eb-4ba0-b0b9-ampincluded",
+ "name": "testExisting_script_ampincluded",
+ "key": "testExisting_script_ampincluded",
+ "description": "",
+ "script": " ",
+ "categoryId": 304,
+ "createdDate": "2022-10-20T00:41:26.163",
+ "modifiedDate": "2022-10-20T00:41:26.163"
+ },
+ {
+ "ssjsActivityId": "39f6a488-20eb-4ba0-b0b9-mixed",
+ "name": "testExisting_script_mixed",
+ "key": "testExisting_script_mixed",
+ "description": "",
+ "script": " line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2;\n collapsed to line2 because it's assumed HTML\n",
+ "categoryId": 304,
+ "createdDate": "2022-10-20T00:41:26.163",
+ "modifiedDate": "2022-10-20T00:41:26.163"
}
]
}
diff --git a/test/resources/9999999/legacy/v1/beta/mobile/keyword/get-response.json b/test/resources/9999999/legacy/v1/beta/mobile/keyword/get-response.json
index b256ebe20..8b716a497 100644
--- a/test/resources/9999999/legacy/v1/beta/mobile/keyword/get-response.json
+++ b/test/resources/9999999/legacy/v1/beta/mobile/keyword/get-response.json
@@ -39,7 +39,7 @@
"createdBy": { "id": "abcabcabc", "name": "xyz app user" },
"restriction": "NONE",
"keywordType": "NORMAL",
- "responseMessage": "line1\nline2",
+ "responseMessage": "line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2\nline3",
"isInherited": false,
"decodedId": "9e2192ab-f611-4039-86a8-7ce0ccf3a453"
}
diff --git a/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json b/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json
index 8cf078833..ff19924a8 100644
--- a/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json
+++ b/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json
@@ -8,7 +8,7 @@
"lastUpdated": "2023-03-08T16:30:00Z",
"type": "ExactTarget.Mobile.Sms.Core.Entities.SmsMessageEntity",
"name": "testExisting_mobileMessage",
- "text": "test message jb secret",
+ "text": "line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2\nline3",
"origin": "SMS Send",
"code": {
"id": "RXBwc0JoNk9jVTY0YWJNWFZDaGxvdzo4MTow",
diff --git a/test/resources/9999999/messaging/v1/sms/definitions/post-response.json b/test/resources/9999999/messaging/v1/sms/definitions/post-response.json
index d78803aa8..6067d13eb 100644
--- a/test/resources/9999999/messaging/v1/sms/definitions/post-response.json
+++ b/test/resources/9999999/messaging/v1/sms/definitions/post-response.json
@@ -6,7 +6,9 @@
"status": "Active",
"createdDate": "2022-11-07T02:24:00",
"modifiedDate": "2022-11-07T02:25:00",
- "content": { "message": "\n%%[\n SET @key = 'new secret'\n]%%\n" },
+ "content": {
+ "message": "\n%%[\n SET @key = 'new secret'\n]%%\n%%[\n\nSET @unsubMessages = 'UnsubscribeSMSMessages_DEV'\nSET @unsubEvents = 'UnsubscribeSMS_DEV'\n\nSET @num = concat('+',[MOBILE_NUMBER])\nSET @rs= RetrieveSalesforceObjects('Contact','Id,et4ae5__HasOptedOutOfMobile__c', 'MobilePhone', '=',@num) \nSET @count = rowCount(@rs)\nVAR @response\nSET @rx = '^\\+((?:9[679]\\d8[035789]\\d|6[789]\\d|5[90]\\d|42\\d|3[578]\\d|2[1-689]\\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'\nSET @prefix = concat('+',RegExMatch(@num, @rx, 1))\nIF @count>0 THEN\n\tFOR @i = 1 TO @count DO\n\t\tSET @sk = Field(Row(@rs,@i),'Id')\n\t\tIF Field(Row(@rs,1),'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN\n\t\t\tSET @result = UpdateSingleSalesforceObject('Contact',@sk,'et4ae5__HasOptedOutOfMobile__c','true')\n\t\t\tIF @result == 0 THEN \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Error Updating')\n\t\t\tELSE \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Successfully Unsubscribed')\n\t\t\tENDIF\n\t\tELSE \n\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Already Unsubscribed')\n\t\tENDIF\n\n\tNEXT @i\n\n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'Found')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='You have unsubscribed and will no longer receive any messages.|'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nELSE \n\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'Status', 'Not Found') \n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'NotFound')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='Sorry, we could not find you'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nENDIF\n]%%\n%%=v(@response)=%%"
+ },
"subscriptions": {
"shortCode": "4912312345678",
"countryCode": "",
diff --git a/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/get-response.json b/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/get-response.json
index e42c625ff..4a154f3d0 100644
--- a/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/get-response.json
+++ b/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/get-response.json
@@ -7,7 +7,9 @@
"status": "Active",
"createdDate": "2022-11-07T02:24:00",
"modifiedDate": "2022-11-07T02:25:00",
- "content": { "message": "%%[ SET @key = 'secret' ]%%" },
+ "content": {
+ "message": "line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2\nline3 %%[ SET @key = 'secret' ]%%\n%%[\n\nSET @unsubMessages = 'UnsubscribeSMSMessages_DEV'\nSET @unsubEvents = 'UnsubscribeSMS_DEV'\n\nSET @num = concat('+',[MOBILE_NUMBER])\nSET @rs= RetrieveSalesforceObjects('Contact','Id,et4ae5__HasOptedOutOfMobile__c', 'MobilePhone', '=',@num) \nSET @count = rowCount(@rs)\nVAR @response\nSET @rx = '^\\+((?:9[679]\\d8[035789]\\d|6[789]\\d|5[90]\\d|42\\d|3[578]\\d|2[1-689]\\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'\nSET @prefix = concat('+',RegExMatch(@num, @rx, 1))\nIF @count>0 THEN\n\tFOR @i = 1 TO @count DO\n\t\tSET @sk = Field(Row(@rs,@i),'Id')\n\t\tIF Field(Row(@rs,1),'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN\n\t\t\tSET @result = UpdateSingleSalesforceObject('Contact',@sk,'et4ae5__HasOptedOutOfMobile__c','true')\n\t\t\tIF @result == 0 THEN \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Error Updating')\n\t\t\tELSE \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Successfully Unsubscribed')\n\t\t\tENDIF\n\t\tELSE \n\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Already Unsubscribed')\n\t\tENDIF\n\n\tNEXT @i\n\n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'Found')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='You have unsubscribed and will no longer receive any messages.|'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nELSE \n\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'Status', 'Not Found') \n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'NotFound')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='Sorry, we could not find you'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nENDIF\n]%%\n%%=v(@response)=%%"
+ },
"subscriptions": {
"shortCode": "4912312345678",
"countryCode": "",
diff --git a/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/patch-response.json b/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/patch-response.json
index e42c625ff..75fb1c122 100644
--- a/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/patch-response.json
+++ b/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/patch-response.json
@@ -7,7 +7,9 @@
"status": "Active",
"createdDate": "2022-11-07T02:24:00",
"modifiedDate": "2022-11-07T02:25:00",
- "content": { "message": "%%[ SET @key = 'secret' ]%%" },
+ "content": {
+ "message": "%%[ SET @key = 'secret' ]%%\n%%[\n\nSET @unsubMessages = 'UnsubscribeSMSMessages_DEV'\nSET @unsubEvents = 'UnsubscribeSMS_DEV'\n\nSET @num = concat('+',[MOBILE_NUMBER])\nSET @rs= RetrieveSalesforceObjects('Contact','Id,et4ae5__HasOptedOutOfMobile__c', 'MobilePhone', '=',@num) \nSET @count = rowCount(@rs)\nVAR @response\nSET @rx = '^\\+((?:9[679]\\d8[035789]\\d|6[789]\\d|5[90]\\d|42\\d|3[578]\\d|2[1-689]\\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'\nSET @prefix = concat('+',RegExMatch(@num, @rx, 1))\nIF @count>0 THEN\n\tFOR @i = 1 TO @count DO\n\t\tSET @sk = Field(Row(@rs,@i),'Id')\n\t\tIF Field(Row(@rs,1),'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN\n\t\t\tSET @result = UpdateSingleSalesforceObject('Contact',@sk,'et4ae5__HasOptedOutOfMobile__c','true')\n\t\t\tIF @result == 0 THEN \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Error Updating')\n\t\t\tELSE \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Successfully Unsubscribed')\n\t\t\tENDIF\n\t\tELSE \n\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Already Unsubscribed')\n\t\tENDIF\n\n\tNEXT @i\n\n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'Found')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='You have unsubscribed and will no longer receive any messages.|'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nELSE \n\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'Status', 'Not Found') \n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'NotFound')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='Sorry, we could not find you'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nENDIF\n]%%\n%%=v(@response)=%%"
+ },
"subscriptions": {
"shortCode": "4912312345678",
"countryCode": "",
diff --git a/test/resources/9999999/mobileKeyword/build-expected.amp b/test/resources/9999999/mobileKeyword/build-expected.amp
index f8be7bb82..d5ac0a44d 100644
--- a/test/resources/9999999/mobileKeyword/build-expected.amp
+++ b/test/resources/9999999/mobileKeyword/build-expected.amp
@@ -1,2 +1,6 @@
line1
-line2
\ No newline at end of file
+%%[
+ SET @test = 'foobar'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
diff --git a/test/resources/9999999/mobileKeyword/get-expected.amp b/test/resources/9999999/mobileKeyword/get-expected.amp
index f8be7bb82..f525314af 100644
--- a/test/resources/9999999/mobileKeyword/get-expected.amp
+++ b/test/resources/9999999/mobileKeyword/get-expected.amp
@@ -1,2 +1,6 @@
line1
-line2
\ No newline at end of file
+%%[
+ SET @test = 'bla bla'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
diff --git a/test/resources/9999999/mobileKeyword/post-create-expected.amp b/test/resources/9999999/mobileKeyword/post-create-expected.amp
index f8be7bb82..c0d0fb45c 100644
--- a/test/resources/9999999/mobileKeyword/post-create-expected.amp
+++ b/test/resources/9999999/mobileKeyword/post-create-expected.amp
@@ -1,2 +1,2 @@
line1
-line2
\ No newline at end of file
+line2
diff --git a/test/resources/9999999/mobileKeyword/template-expected.amp b/test/resources/9999999/mobileKeyword/template-expected.amp
index f8be7bb82..936f8c5c5 100644
--- a/test/resources/9999999/mobileKeyword/template-expected.amp
+++ b/test/resources/9999999/mobileKeyword/template-expected.amp
@@ -1,2 +1,6 @@
line1
-line2
\ No newline at end of file
+%%[
+ SET @test = '{{{description}}}'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
diff --git a/test/resources/9999999/mobileMessage/build-expected.amp b/test/resources/9999999/mobileMessage/build-expected.amp
index 2717f2fb5..d5ac0a44d 100644
--- a/test/resources/9999999/mobileMessage/build-expected.amp
+++ b/test/resources/9999999/mobileMessage/build-expected.amp
@@ -1 +1,6 @@
-test message jb target secret
\ No newline at end of file
+line1
+%%[
+ SET @test = 'foobar'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
diff --git a/test/resources/9999999/mobileMessage/get-expected.amp b/test/resources/9999999/mobileMessage/get-expected.amp
index 9e2605fbc..f525314af 100644
--- a/test/resources/9999999/mobileMessage/get-expected.amp
+++ b/test/resources/9999999/mobileMessage/get-expected.amp
@@ -1 +1,6 @@
-test message jb secret
\ No newline at end of file
+line1
+%%[
+ SET @test = 'bla bla'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
diff --git a/test/resources/9999999/mobileMessage/post-create-expected.amp b/test/resources/9999999/mobileMessage/post-create-expected.amp
index 5cd044454..3e5727b71 100644
--- a/test/resources/9999999/mobileMessage/post-create-expected.amp
+++ b/test/resources/9999999/mobileMessage/post-create-expected.amp
@@ -1 +1 @@
-New Task Available
\ No newline at end of file
+New Task Available
diff --git a/test/resources/9999999/mobileMessage/post-update-expected.amp b/test/resources/9999999/mobileMessage/post-update-expected.amp
index 0639ff611..d389984de 100644
--- a/test/resources/9999999/mobileMessage/post-update-expected.amp
+++ b/test/resources/9999999/mobileMessage/post-update-expected.amp
@@ -1 +1 @@
-test message jb new
\ No newline at end of file
+test message jb new
diff --git a/test/resources/9999999/mobileMessage/template-expected.amp b/test/resources/9999999/mobileMessage/template-expected.amp
index bb1bc863d..936f8c5c5 100644
--- a/test/resources/9999999/mobileMessage/template-expected.amp
+++ b/test/resources/9999999/mobileMessage/template-expected.amp
@@ -1 +1,6 @@
-test message jb {{{secret}}}
\ No newline at end of file
+line1
+%%[
+ SET @test = '{{{description}}}'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
diff --git a/test/resources/9999999/script/get_ampincluded-expected.json b/test/resources/9999999/script/get_ampincluded-expected.json
new file mode 100644
index 000000000..b801f5140
--- /dev/null
+++ b/test/resources/9999999/script/get_ampincluded-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "",
+ "key": "testExisting_script_ampincluded",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testExisting_script_ampincluded",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/get_ampincluded-expected.ssjs b/test/resources/9999999/script/get_ampincluded-expected.ssjs
new file mode 100644
index 000000000..8c5acec4b
--- /dev/null
+++ b/test/resources/9999999/script/get_ampincluded-expected.ssjs
@@ -0,0 +1,5 @@
+line1
+%%[
+ SET @test = 'bla bla'
+]%%
+line2 %%= v(@test) =%% still line2 line3
diff --git a/test/resources/9999999/script/get_ampscript-expected.html b/test/resources/9999999/script/get_ampscript-expected.html
new file mode 100644
index 000000000..8c5acec4b
--- /dev/null
+++ b/test/resources/9999999/script/get_ampscript-expected.html
@@ -0,0 +1,5 @@
+line1
+%%[
+ SET @test = 'bla bla'
+]%%
+line2 %%= v(@test) =%% still line2 line3
diff --git a/test/resources/9999999/script/get_ampscript-expected.json b/test/resources/9999999/script/get_ampscript-expected.json
new file mode 100644
index 000000000..949cbc253
--- /dev/null
+++ b/test/resources/9999999/script/get_ampscript-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "",
+ "key": "testExisting_script_ampscript",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testExisting_script_ampscript",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/get_mixed-expected.html b/test/resources/9999999/script/get_mixed-expected.html
new file mode 100644
index 000000000..87ae1266f
--- /dev/null
+++ b/test/resources/9999999/script/get_mixed-expected.html
@@ -0,0 +1,9 @@
+
+line1
+%%[
+ SET @test = 'bla bla'
+]%%
+line2 %%= v(@test) =%% still line2; collapsed to line2 because
+it's assumed HTML
diff --git a/test/resources/9999999/script/get_mixed-expected.json b/test/resources/9999999/script/get_mixed-expected.json
new file mode 100644
index 000000000..c217d3cb1
--- /dev/null
+++ b/test/resources/9999999/script/get_mixed-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "",
+ "key": "testExisting_script_mixed",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testExisting_script_mixed",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/transactionalSMS/build-expected.amp b/test/resources/9999999/transactionalSMS/build-expected.amp
index 006734caf..90327ec0e 100644
--- a/test/resources/9999999/transactionalSMS/build-expected.amp
+++ b/test/resources/9999999/transactionalSMS/build-expected.amp
@@ -1,4 +1,108 @@
-
+line1
+%%[
+ SET @test = 'foobar'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
%%[
SET @key = 'target secret'
]%%
+
+%%[
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
+ SET @num = concat('+', [MOBILE_NUMBER])
+ SET @rs = RetrieveSalesforceObjects(
+ 'Contact',
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
+ 'MobilePhone',
+ '=',
+ @num
+ )
+ SET @count = rowCount(@rs)
+ VAR @response
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
+ IF @count>0 THEN
+ FOR @I = 1 TO @COUNT DO
+ SET @sk = Field(Row(@rs, @i), 'Id')
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
+ IF @result == 0 THEN
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Error Updating'
+ )
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Successfully Unsubscribed'
+ )
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Already Unsubscribed'
+ )
+ ENDIF
+ NEXT @i
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'Found'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'Status',
+ 'Not Found'
+ )
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'NotFound'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'Sorry, we could not find you'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ENDIF
+]%%
+%%=v(@response)=%%
diff --git a/test/resources/9999999/transactionalSMS/get-expected.amp b/test/resources/9999999/transactionalSMS/get-expected.amp
index e4c5aff95..550ecfdd8 100644
--- a/test/resources/9999999/transactionalSMS/get-expected.amp
+++ b/test/resources/9999999/transactionalSMS/get-expected.amp
@@ -1,4 +1,108 @@
-
+line1
+%%[
+ SET @test = 'bla bla'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
%%[
SET @key = 'secret'
]%%
+
+%%[
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
+ SET @num = concat('+', [MOBILE_NUMBER])
+ SET @rs = RetrieveSalesforceObjects(
+ 'Contact',
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
+ 'MobilePhone',
+ '=',
+ @num
+ )
+ SET @count = rowCount(@rs)
+ VAR @response
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
+ IF @count>0 THEN
+ FOR @I = 1 TO @COUNT DO
+ SET @sk = Field(Row(@rs, @i), 'Id')
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
+ IF @result == 0 THEN
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Error Updating'
+ )
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Successfully Unsubscribed'
+ )
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Already Unsubscribed'
+ )
+ ENDIF
+ NEXT @i
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'Found'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'Status',
+ 'Not Found'
+ )
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'NotFound'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'Sorry, we could not find you'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ENDIF
+]%%
+%%=v(@response)=%%
diff --git a/test/resources/9999999/transactionalSMS/patch-expected.amp b/test/resources/9999999/transactionalSMS/patch-expected.amp
index e4c5aff95..e1ef91076 100644
--- a/test/resources/9999999/transactionalSMS/patch-expected.amp
+++ b/test/resources/9999999/transactionalSMS/patch-expected.amp
@@ -1,4 +1,102 @@
-
%%[
SET @key = 'secret'
]%%
+
+%%[
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
+ SET @num = concat('+', [MOBILE_NUMBER])
+ SET @rs = RetrieveSalesforceObjects(
+ 'Contact',
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
+ 'MobilePhone',
+ '=',
+ @num
+ )
+ SET @count = rowCount(@rs)
+ VAR @response
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
+ IF @count>0 THEN
+ FOR @I = 1 TO @COUNT DO
+ SET @sk = Field(Row(@rs, @i), 'Id')
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
+ IF @result == 0 THEN
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Error Updating'
+ )
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Successfully Unsubscribed'
+ )
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Already Unsubscribed'
+ )
+ ENDIF
+ NEXT @i
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'Found'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'Status',
+ 'Not Found'
+ )
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'NotFound'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'Sorry, we could not find you'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ENDIF
+]%%
+%%=v(@response)=%%
diff --git a/test/resources/9999999/transactionalSMS/post-expected.amp b/test/resources/9999999/transactionalSMS/post-expected.amp
index a1f4bd04f..b11a84731 100644
--- a/test/resources/9999999/transactionalSMS/post-expected.amp
+++ b/test/resources/9999999/transactionalSMS/post-expected.amp
@@ -1,4 +1,102 @@
-
%%[
SET @key = 'new secret'
]%%
+
+%%[
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
+ SET @num = concat('+', [MOBILE_NUMBER])
+ SET @rs = RetrieveSalesforceObjects(
+ 'Contact',
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
+ 'MobilePhone',
+ '=',
+ @num
+ )
+ SET @count = rowCount(@rs)
+ VAR @response
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
+ IF @count>0 THEN
+ FOR @I = 1 TO @COUNT DO
+ SET @sk = Field(Row(@rs, @i), 'Id')
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
+ IF @result == 0 THEN
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Error Updating'
+ )
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Successfully Unsubscribed'
+ )
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Already Unsubscribed'
+ )
+ ENDIF
+ NEXT @i
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'Found'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'Status',
+ 'Not Found'
+ )
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'NotFound'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'Sorry, we could not find you'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ENDIF
+]%%
+%%=v(@response)=%%
diff --git a/test/resources/9999999/transactionalSMS/template-expected.amp b/test/resources/9999999/transactionalSMS/template-expected.amp
index 29e5fcafe..26bc6dc2f 100644
--- a/test/resources/9999999/transactionalSMS/template-expected.amp
+++ b/test/resources/9999999/transactionalSMS/template-expected.amp
@@ -1,4 +1,108 @@
-
+line1
+%%[
+ SET @test = '{{{description}}}'
+]%%
+line2 %%= v(@test) =%% still line2
+line3
%%[
SET @key = '{{{secret}}}'
]%%
+
+%%[
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
+ SET @num = concat('+', [MOBILE_NUMBER])
+ SET @rs = RetrieveSalesforceObjects(
+ 'Contact',
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
+ 'MobilePhone',
+ '=',
+ @num
+ )
+ SET @count = rowCount(@rs)
+ VAR @response
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
+ IF @count>0 THEN
+ FOR @I = 1 TO @COUNT DO
+ SET @sk = Field(Row(@rs, @i), 'Id')
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
+ IF @result == 0 THEN
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Error Updating'
+ )
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Successfully Unsubscribed'
+ )
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'ContactId',
+ @sk,
+ 'Status',
+ 'Already Unsubscribed'
+ )
+ ENDIF
+ NEXT @i
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'Found'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ELSE
+ InsertData(
+ @unsubEvents,
+ 'MobileNumber',
+ @num,
+ 'Message',
+ [MSG(0).NOUNS],
+ 'Status',
+ 'Not Found'
+ )
+ SET @msg = Lookup(
+ @unsubMessages,
+ 'Message',
+ 'Prefix',
+ @prefix,
+ 'Type',
+ 'NotFound'
+ )
+ IF Length(@msg) == 0 THEN
+ SET @response = 'Sorry, we could not find you'
+ ELSE
+ SET @response = @msg
+ ENDIF
+ ENDIF
+]%%
+%%=v(@response)=%%
diff --git a/test/type.script.test.js b/test/type.script.test.js
index d50fda9a1..215136ab5 100644
--- a/test/type.script.test.js
+++ b/test/type.script.test.js
@@ -20,22 +20,21 @@ describe('type: script', () => {
const retrieve = await handler.retrieve('testInstance/testBU', ['script']);
// THEN
assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
-
// retrieve result
assert.equal(
retrieve['testInstance/testBU'].script
? Object.keys(retrieve['testInstance/testBU'].script).length
: 0,
- 2,
- 'only 2 scripts expected in retrieve response'
+ 5,
+ 'only 5 scripts expected in retrieve response'
);
// get results from cache
const result = cache.getCache();
assert.equal(
result.script ? Object.keys(result.script).length : 0,
- 2,
- 'only 2 scripts expected'
+ 5,
+ 'only 5 scripts expected'
);
// normal test
assert.deepEqual(
@@ -49,6 +48,7 @@ describe('type: script', () => {
file(testUtils.getExpectedFile('9999999', 'script', 'get', 'ssjs'))
);
+ // test with no script tag
assert.deepEqual(
await testUtils.getActualJson('testExisting_script_noScriptTag', 'script'),
await testUtils.getExpectedJson('9999999', 'script', 'get_noScriptTag'),
@@ -63,6 +63,47 @@ describe('type: script', () => {
file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'ssjs'))
).to.not.exist;
+ // test with ampscript
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script_ampscript', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get_ampscript'),
+ 'returned metadata was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualFile('testExisting_script_ampscript', 'script', 'html'))
+ ).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'get_ampscript', 'html'))
+ );
+ expect(file(testUtils.getActualFile('testExisting_script_ampscript', 'script', 'ssjs')))
+ .to.not.exist;
+
+ // test with mixed code (ampscript inside of ssjs)
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script_ampincluded', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get_ampincluded'),
+ 'returned metadata was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualFile('testExisting_script_ampincluded', 'script', 'html'))
+ ).to.not.exist;
+ expect(
+ file(testUtils.getActualFile('testExisting_script_ampincluded', 'script', 'ssjs'))
+ ).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'get_ampincluded', 'ssjs'))
+ );
+
+ // test with mixed code (ssjs and ampscript side-by-side)
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script_mixed', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get_mixed'),
+ 'returned metadata was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualFile('testExisting_script_mixed', 'script', 'html'))
+ ).to.equal(file(testUtils.getExpectedFile('9999999', 'script', 'get_mixed', 'html')));
+ expect(file(testUtils.getActualFile('testExisting_script_mixed', 'script', 'ssjs'))).to
+ .not.exist;
+
assert.equal(
testUtils.getAPIHistoryLength(),
3,
@@ -122,8 +163,8 @@ describe('type: script', () => {
const result = cache.getCache();
assert.equal(
result.script ? Object.keys(result.script).length : 0,
- 2,
- 'two scripts in cache expected'
+ 5,
+ '5 scripts in cache expected'
);
assert.deepEqual(
await testUtils.getActualJson('testExisting_script', 'script'),
@@ -162,8 +203,8 @@ describe('type: script', () => {
const result = cache.getCache();
assert.equal(
result.script ? Object.keys(result.script).length : 0,
- 2,
- 'two scripts in cache expected'
+ 5,
+ '5 scripts in cache expected'
);
expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.not
@@ -189,8 +230,8 @@ describe('type: script', () => {
const result = cache.getCache();
assert.equal(
result.script ? Object.keys(result.script).length : 0,
- 3,
- 'three scripts expected'
+ 6,
+ '6 scripts expected'
);
// confirm created item
assert.deepEqual(
@@ -198,15 +239,14 @@ describe('type: script', () => {
await testUtils.getExpectedJson('9999999', 'script', 'post'),
'returned metadata was not equal expected for insert script'
);
- expect(file(testUtils.getActualFile('testNew_script', 'script', 'ssjs'))).to.equal(
- file(testUtils.getExpectedFile('9999999', 'script', 'post', 'ssjs'))
- );
// confirm updated item
assert.deepEqual(
await testUtils.getActualJson('testExisting_script', 'script'),
await testUtils.getExpectedJson('9999999', 'script', 'patch'),
'returned metadata was not equal expected for insert script'
);
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'html'))).to.not
+ .exist;
expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.equal(
file(testUtils.getExpectedFile('9999999', 'script', 'patch', 'ssjs'))
);
diff --git a/test/utils.js b/test/utils.js
index f6404ee8c..98021ae80 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -156,6 +156,9 @@ export function mockSetup(isDeploy) {
'node_modules/prettier-plugin-sql': fsmock.load(
path.resolve(__dirname, '../node_modules/prettier-plugin-sql')
),
+ 'node_modules/beauty-amp-core2': fsmock.load(
+ path.resolve(__dirname, '../node_modules/beauty-amp-core2')
+ ),
'node_modules/node-sql-parser': fsmock.load(
path.resolve(__dirname, '../node_modules/node-sql-parser')
),