Skip to content

Commit

Permalink
#870: add tests for execute automation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Jul 5, 2023
1 parent 75a74d8 commit 7b3b60e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,10 @@ class Automation extends MetadataType {
}
}
}
if (Util.OPTIONS.execute) {
Util.logger.info(`Executing: ${this.definition.type}`);
await this.execute(Object.keys(metadataMap));
}
}
/**
* helper for {@link Automation.postDeployTasks}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>ScheduleResponse</wsa:Action>
<wsa:MessageID>urn:uuid:b58a82d9-a251-4be4-b50c-bd300d71601d</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:9d3dbeb3-68b7-4f0a-b0af-04855dc0fd1e</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-5ff54ff3-2408-496a-b4ea-6df5e9ebee03">
<wsu:Created>2023-07-05T10:29:58Z</wsu:Created>
<wsu:Expires>2023-07-05T10:34:58Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<ScheduleResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<Results>
<Result>
<StatusCode>OK</StatusCode>
<StatusMessage>Program scheduled.</StatusMessage>
<RequestID>3a677ca8-5423-4d59-a1bb-c5fbe1c87197</RequestID>
<Object>
<PartnerKey xsi:nil="true" />
<ObjectID xsi:nil="true" />
<Recurrence xsi:type="DailyRecurrence">
<DailyRecurrencePatternType>Interval</DailyRecurrencePatternType>
<DayInterval>1</DayInterval>
</Recurrence>
<RecurrenceType>Daily</RecurrenceType>
<RecurrenceRangeType>EndAfter</RecurrenceRangeType>
<StartDateTime>2023-07-05T16:00:57</StartDateTime>
<Occurrences>1</Occurrences>
<TimeZone>
<PartnerKey xsi:nil="true" />
<ID>5</ID>
<ObjectID xsi:nil="true" />
</TimeZone>
</Object>
<Task />
</Result>
</Results>
<OverallStatus>OK</OverallStatus>
<OverallStatusMessage />
<RequestID>cfe97488-3c5e-49a9-b338-c0e9f6b6f684</RequestID>
</ScheduleResponseMsg>
</soap:Body>
</soap:Envelope>
68 changes: 65 additions & 3 deletions test/type.automation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,57 @@ describe('type: automation', () => {
)
);

assert.equal(
testUtils.getAPIHistoryLength(),
16,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should update & start an automation with --execute option', async () => {
// WHEN
handler.setOptions({ execute: true });
await handler.deploy(
'testInstance/testBU',
['automation'],
['testExisting_automation']
);
// THEN
assert.equal(
process.exitCode,
false,
'deploy with --execute should not have thrown an error'
);

// get results from cache
const result = cache.getCache();
assert.equal(
result.automation ? Object.keys(result.automation).length : 0,
1,
'one automation expected'
);

// update
assert.deepEqual(
await testUtils.getActualJson('testExisting_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'update'),
'returned metadata was not equal expected for update'
);
// check if MD file was created and equals expectations
expect(file(testUtils.getActualDoc('testNew_automation', 'automation'))).to.equal(
expect(file(testUtils.getActualDoc('testExisting_automation', 'automation'))).to.equal(
file(
testUtils.getExpectedFile(
'9999999',
'automation',
'create-testNew_automation',
'update-testExisting_automation',
'md'
)
)
);

assert.equal(
testUtils.getAPIHistoryLength(),
16,
19,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
Expand Down Expand Up @@ -256,4 +292,30 @@ describe('type: automation', () => {
return;
});
});
describe('Execute ================', () => {
it('Should start an automation by key', async () => {
const execute = await handler.execute('testInstance/testBU', 'automation', [
'testExisting_automation',
]);
assert.equal(process.exitCode, false, 'execute should not have thrown an error');
assert.equal(execute, true, 'automation was supposed to be executed');
return;
});
it('Should start an automation selected via --like', async () => {
handler.setOptions({ like: { key: 'testExist%automation' } });
const execute = await handler.execute('testInstance/testBU', 'automation');
assert.equal(process.exitCode, false, 'execute should not have thrown an error');
assert.equal(execute, true, 'automation was supposed to be executed');
return;
});
it('Should not start executing an automation because key and --like was specified', async () => {
handler.setOptions({ like: { key: 'testExisting%' } });
const execute = await handler.execute('testInstance/testBU', 'automation', [
'testExisting_automation',
]);
assert.equal(process.exitCode, true, 'execute should not have thrown an error');
assert.equal(execute, false, 'automation was not supposed to be executed');
return;
});
});
});

0 comments on commit 7b3b60e

Please sign in to comment.