Skip to content

Commit

Permalink
#782: add RETRIEVE test to mobileKeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Mar 29, 2023
1 parent 3836b4f commit 3ebc727
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
155 changes: 155 additions & 0 deletions test/mobileKeyword.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
const chai = require('chai');
const chaiFiles = require('chai-files');
const assert = chai.assert;
chai.use(chaiFiles);
const expect = chai.expect;
const file = chaiFiles.file;
const cache = require('../lib/util/cache');
const testUtils = require('./utils');
const handler = require('../lib/index');

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

describe('Retrieve ================', () => {
it('Should retrieve a mobileKeyword', async () => {
// WHEN
await handler.retrieve('testInstance/testBU', ['mobileKeyword']);
// THEN
assert.equal(!!process.exitCode, false, 'retrieve should not have thrown an error');
// get results from cache
const result = cache.getCache();
assert.equal(
result.mobileKeyword ? Object.keys(result.mobileKeyword).length : 0,
1,
'only 1 mobileKeywords expected'
);
assert.deepEqual(
await testUtils.getActualJson('testExisting_keyword', 'mobileKeyword'),
await testUtils.getExpectedJson('9999999', 'mobileKeyword', 'get'),
'saved JSON was not equal expected'
);
expect(
file(testUtils.getActualFile('testExisting_keyword', 'mobileKeyword', 'amp'))
).to.equal(file(testUtils.getExpectedFile('9999999', 'mobileKeyword', 'get', 'amp')));
assert.equal(
testUtils.getAPIHistoryLength(),
2,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
// describe('Deploy ================', () => {
// beforeEach(() => {
// testUtils.mockSetup(true);
// });
// it('Should create & upsert a mobileKeyword', async () => {
// // WHEN
// await handler.deploy('testInstance/testBU', ['mobileKeyword']);
// // THEN
// assert.equal(!!process.exitCode, false, 'deploy should not have thrown an error');
// // get results from cache
// const result = cache.getCache();
// assert.equal(
// result.mobileKeyword ? Object.keys(result.mobileKeyword).length : 0,
// 2,
// '2 mobileKeywords expected'
// );
// // confirm created item
// assert.deepEqual(
// await testUtils.getActualJson('NTQ3Ojc4OjA', 'mobileKeyword'),
// await testUtils.getExpectedJson('9999999', 'mobileKeyword', 'post-create'),
// 'returned JSON was not equal expected for insert mobileKeyword'
// );
// expect(file(testUtils.getActualFile('NTQ3Ojc4OjA', 'mobileKeyword', 'amp'))).to.equal(
// file(testUtils.getExpectedFile('9999999', 'mobileKeyword', 'post-create', 'amp'))
// );

// // confirm updated item
// assert.deepEqual(
// await testUtils.getActualJson('NTIzOjc4OjA', 'mobileKeyword'),
// await testUtils.getExpectedJson('9999999', 'mobileKeyword', 'post-update'), // watch out - mobileKeyword api wants put instead of patch for updates
// 'returned JSON was not equal expected for update mobileKeyword'
// );
// expect(file(testUtils.getActualFile('NTIzOjc4OjA', 'mobileKeyword', 'amp'))).to.equal(
// file(testUtils.getExpectedFile('9999999', 'mobileKeyword', 'post-update', 'amp'))
// );

// // check number of API calls
// assert.equal(
// testUtils.getAPIHistoryLength(),
// 7,
// 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
// );
// return;
// });
// });
// describe('Templating ================', () => {
// it('Should create a mobileKeyword template via buildTemplate and build it', async () => {
// // download first before we test buildTemplate
// await handler.retrieve('testInstance/testBU', ['mobileKeyword']);
// // buildTemplate
// const result = await handler.buildTemplate(
// 'testInstance/testBU',
// 'mobileKeyword',
// ['NTIzOjc4OjA'],
// 'testSourceMarket'
// );
// assert.equal(
// !!process.exitCode,
// false,
// 'buildTemplate should not have thrown an error'
// );

// assert.equal(
// result.mobileKeyword ? Object.keys(result.mobileKeyword).length : 0,
// 1,
// 'only one mobileKeyword expected'
// );
// assert.deepEqual(
// await testUtils.getActualTemplateJson('NTIzOjc4OjA', 'mobileKeyword'),
// await testUtils.getExpectedJson('9999999', 'mobileKeyword', 'template'),
// 'returned template JSON was not equal expected'
// );
// expect(
// file(testUtils.getActualTemplateFile('NTIzOjc4OjA', 'mobileKeyword', 'amp'))
// ).to.equal(
// file(testUtils.getExpectedFile('9999999', 'mobileKeyword', 'template', 'amp'))
// );

// // buildDefinition
// await handler.buildDefinition(
// 'testInstance/testBU',
// 'mobileKeyword',
// 'NTIzOjc4OjA',
// 'testTargetMarket'
// );
// assert.equal(
// !!process.exitCode,
// false,
// 'buildDefinition should not have thrown an error'
// );
// assert.deepEqual(
// await testUtils.getActualDeployJson('NTIzOjc4OjA', 'mobileKeyword'),
// await testUtils.getExpectedJson('9999999', 'mobileKeyword', 'build'),
// 'returned deployment JSON was not equal expected'
// );
// expect(
// file(testUtils.getActualDeployFile('NTIzOjc4OjA', 'mobileKeyword', 'amp'))
// ).to.equal(file(testUtils.getExpectedFile('9999999', 'mobileKeyword', 'build', 'amp')));

// assert.equal(
// testUtils.getAPIHistoryLength(),
// 4,
// 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
// );
// return;
// });
// });
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"createdBy": { "id": "abcabcabc", "name": "xyz app user" },
"restriction": "NONE",
"keywordType": "NORMAL",
"responseMessage": "line1\nline2",
"isInherited": false,
"decodedId": "9e2192ab-f611-4039-86a8-7ce0ccf3a453"
}
Expand Down
2 changes: 2 additions & 0 deletions test/resources/9999999/mobileKeyword/get-expected.amp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
line1
line2
15 changes: 15 additions & 0 deletions test/resources/9999999/mobileKeyword/get-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"createdDate": "2018-03-27T12:37:18.12Z",
"lastUpdated": "2018-03-27T12:37:18.167Z",
"code": {
"code": "4912312345678"
},
"keyword": "testExisting_keyword",
"startDate": "2018-03-27T12:37:18.197Z",
"endDate": "2038-03-27T12:37:18.197Z",
"status": "Active",
"createdBy": { "name": "xyz app user" },
"restriction": "NONE",
"keywordType": "NORMAL",
"isInherited": false
}

0 comments on commit 3ebc727

Please sign in to comment.