Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/850: add test class for fileTransfer #1037

Merged
merged 2 commits into from
Jul 18, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"createdDate": "2022-11-09T05:31:56.477",
"customerKey": "testExisting_fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%% updated via deploy",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"modifiedDate": "2022-11-17T07:13:20.05",
"name": "testExisting_fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"createdDate": "2022-11-09T05:31:56.477",
"customerKey": "testNew_fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%% created on deploy",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"modifiedDate": "2022-11-17T07:13:20.05",
"name": "testNew_fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "72c328ac-f5b0-4e37-91d3-a775666f15a6",
"name": "testExisting_fileTransfer",
"description": "17.11.2022",
"customerKey": "testExisting_fileTransfer",
"fileSpec": "%%Year%% updated via deploy",
"isEncrypted": false,
"isCompressed": false,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"fileTransferLocationId": "41a5ded7-0d98-4910-a15f-d09e7ab0af24",
"isUpload": true,
"isPgp": false,
"isFileSpecLocalized": false,
"createdDate": "2022-11-09T05:31:56.477",
"modifiedDate": "2022-11-17T07:13:20.05"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "72c328ac-f5b0-4e37-91d3-a775666f15a6",
"name": "testNew_fileTransfer",
"description": "17.11.2022",
"customerKey": "testNew_fileTransfer",
"fileSpec": "%%Year%% created on deploy",
"isEncrypted": false,
"isCompressed": false,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"fileTransferLocationId": "41a5ded7-0d98-4910-a15f-d09e7ab0af24",
"isUpload": true,
"isPgp": false,
"isFileSpecLocalized": false,
"createdDate": "2022-11-09T05:31:56.477",
"modifiedDate": "2022-11-17T07:13:20.05"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"page": 1,
"pageSize": 2,
"count": 2,
"items": [
{
"name": "Salesforce Objects & Reports",
"id": "a4a0aff9-ddc5-4608-b0e1-40d0a5133d8f",
"locationTypeId": 4
},
{
"name": "ExactTarget Enhanced FTP",
"id": "41a5ded7-0d98-4910-a15f-d09e7ab0af24",
"locationTypeId": 0,
"relPath": "ExactTarget Enhanced FTP"
}
]
}
15 changes: 15 additions & 0 deletions test/resources/9999999/fileTransfer/build-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"customerKey": "testTemplated_fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%%",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"name": "testTemplated_fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
17 changes: 17 additions & 0 deletions test/resources/9999999/fileTransfer/get-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"createdDate": "2022-11-09T05:31:56.477",
"customerKey": "testExisting_fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%%",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"modifiedDate": "2022-11-17T07:13:20.05",
"name": "testExisting_fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
17 changes: 17 additions & 0 deletions test/resources/9999999/fileTransfer/patch-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"createdDate": "2022-11-09T05:31:56.477",
"customerKey": "testExisting_fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%% updated via deploy",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"modifiedDate": "2022-11-17T07:13:20.05",
"name": "testExisting_fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
17 changes: 17 additions & 0 deletions test/resources/9999999/fileTransfer/post-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"createdDate": "2022-11-09T05:31:56.477",
"customerKey": "testNew_fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%% created on deploy",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"modifiedDate": "2022-11-17T07:13:20.05",
"name": "testNew_fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
15 changes: 15 additions & 0 deletions test/resources/9999999/fileTransfer/template-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"customerKey": "{{{prefix}}}fileTransfer",
"description": "17.11.2022",
"fileSpec": "%%Year%%",
"isCompressed": false,
"isEncrypted": false,
"isFileSpecLocalized": false,
"isPgp": false,
"isUpload": true,
"maxFileAge": 0,
"maxFileAgeScheduleOffset": 0,
"maxImportFrequency": 0,
"name": "{{{prefix}}}fileTransfer",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
186 changes: 186 additions & 0 deletions test/type.fileTransfer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
const chai = require('chai');
const chaiFiles = require('chai-files');
const assert = chai.assert;
chai.use(chaiFiles);
const cache = require('../lib/util/cache');
const testUtils = require('./utils');
const handler = require('../lib/index');

describe('type: fileTransfer', () => {
beforeEach(() => {
testUtils.mockSetup();
});
afterEach(() => {
testUtils.mockReset();
});

describe('Retrieve ================', () => {
it('Should retrieve a fileTransfer', async () => {
// WHEN
await handler.retrieve('testInstance/testBU', ['fileTransfer']);
// THEN
assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
// get results from cache
const result = cache.getCache();
assert.equal(
result.fileTransfer ? Object.keys(result.fileTransfer).length : 0,
1,
'only one fileTransfer expected'
);
assert.deepEqual(
await testUtils.getActualJson('testExisting_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'get'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
3,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
describe('Deploy ================', () => {
beforeEach(() => {
testUtils.mockSetup(true);
});
it('Should create & upsert a fileTransfer', async () => {
// WHEN
await handler.deploy('testInstance/testBU', ['fileTransfer']);
// THEN
assert.equal(process.exitCode, false, 'deploy should not have thrown an error');
// get results from cache
const result = cache.getCache();
assert.equal(
result.fileTransfer ? Object.keys(result.fileTransfer).length : 0,
2,
'two fileTransfers expected'
);
// confirm created item
assert.deepEqual(
await testUtils.getActualJson('testNew_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'post'),
'returned JSON was not equal expected for insert fileTransfer'
);
// confirm updated item
assert.deepEqual(
await testUtils.getActualJson('testExisting_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'patch'),
'returned JSON was not equal expected for update fileTransfer'
);
// check number of API calls
assert.equal(
testUtils.getAPIHistoryLength(),
5,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should change the key during update via --changeKeyValue ');
});
describe('Templating ================', () => {
it('Should create a fileTransfer template via retrieveAsTemplate and build it', async () => {
// buildTemplate
const result = await handler.retrieveAsTemplate(
'testInstance/testBU',
'fileTransfer',
['testExisting_fileTransfer'],
'testSourceMarket'
);
assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error');
assert.equal(
result.fileTransfer ? Object.keys(result.fileTransfer).length : 0,
1,
'only one fileTransfer expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'template'),
'returned template JSON was not equal expected'
);
// buildDefinition
await handler.buildDefinition(
'testInstance/testBU',
'fileTransfer',
'testExisting_fileTransfer',
'testTargetMarket'
);
assert.equal(
process.exitCode,
false,
'buildDefinition should not have thrown an error'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'build'),
'returned deployment JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
3,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should create a fileTransfer template via buildTemplate and build it', async () => {
// download first before we test buildTemplate
await handler.retrieve('testInstance/testBU', ['fileTransfer']);
// buildTemplate
const result = await handler.buildTemplate(
'testInstance/testBU',
'fileTransfer',
['testExisting_fileTransfer'],
'testSourceMarket'
);
assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error');
assert.equal(
result.fileTransfer ? Object.keys(result.fileTransfer).length : 0,
1,
'only one fileTransfer expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'template'),
'returned template JSON was not equal expected'
);
// buildDefinition
await handler.buildDefinition(
'testInstance/testBU',
'fileTransfer',
'testExisting_fileTransfer',
'testTargetMarket'
);
assert.equal(
process.exitCode,
false,
'buildDefinition should not have thrown an error'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_fileTransfer', 'fileTransfer'),
await testUtils.getExpectedJson('9999999', 'fileTransfer', 'build'),
'returned deployment JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
3,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
describe('Delete ================', () => {
it('Should NOT delete the item', async () => {
// WHEN
await handler.deleteByKey('testInstance/testBU', 'fileTransfer', [
'testExisting_fileTranfer',
]);
// THEN
assert.equal(
process.exitCode,
1,
'deleteByKey should have thrown an error due to lack of support'
);
return;
});
});
});