Skip to content

Commit 0d16294

Browse files
authored
SITES-24645: [Importer] Add validation check for jobId while creating an import URL (#373)
## Related Issues [SITES-24645](https://jira.corp.adobe.com/browse/SITES-24645) We want to add a validation check for jobId in spacecat-shared while creating an import-url. We do not want an import-url entry in the DB without the jobId attribute.
1 parent 0362ba4 commit 0d16294

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/spacecat-shared-data-access/src/models/importer/import-url.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export const createImportUrl = (data) => {
105105
throw new Error(`Invalid Url: ${newState.url}`);
106106
}
107107

108+
if (!hasText(newState.jobId)) {
109+
throw new Error(`Invalid Job ID: ${newState.jobId}`);
110+
}
111+
108112
if (!Object.values(ImportUrlStatus).includes(newState.status)) {
109113
throw new Error(`Invalid Import URL status: ${newState.status}`);
110114
}

packages/spacecat-shared-data-access/test/unit/models/importer/import-url.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ describe('ImportUrl Model tests', () => {
4242
it('throws an error if status is invalid', () => {
4343
expect(() => createImportUrl({ ...validImportUrlData, status: 'invalid' })).to.throw('Invalid Import URL status: invalid');
4444
});
45+
46+
it('throws an error if jobId is not a valid string', () => {
47+
expect(() => createImportUrl({ ...validImportUrlData, jobId: null })).to.throw('Invalid Job ID: null');
48+
});
4549
});
4650
describe('Import URL Functionality Tests', () => {
4751
let importUrl;

packages/spacecat-shared-data-access/test/unit/service/import-url/index.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('Import Url Tests', () => {
6969
const mockImportUrl = {
7070
id: 'test-id',
7171
status: 'RUNNING',
72+
jobId: 'test-job-id',
7273
url: 'https://www.test.com',
7374
};
7475
await exportedFunctions.createNewImportUrl(mockImportUrl);
@@ -80,6 +81,7 @@ describe('Import Url Tests', () => {
8081
it('should update an existing importUrl with the correct status', async () => {
8182
const mockImportUrl = {
8283
id: 'test-id',
84+
jobId: 'test-job-id',
8385
status: 'RUNNING',
8486
url: 'https://www.test.com',
8587
};
@@ -97,6 +99,7 @@ describe('Import Url Tests', () => {
9799
it('should throw an error when the importUrl does not exist', async () => {
98100
const mockImportUrl = {
99101
id: 'test-id',
102+
jobId: 'test-job-id',
100103
status: 'RUNNING',
101104
url: 'https://www.test.com',
102105
};

0 commit comments

Comments
 (0)