Skip to content

Commit

Permalink
SITES-24645: [Importer] Add validation check for jobId while creating…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
swetabar committed Sep 19, 2024
1 parent 0362ba4 commit 0d16294
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export const createImportUrl = (data) => {
throw new Error(`Invalid Url: ${newState.url}`);
}

if (!hasText(newState.jobId)) {
throw new Error(`Invalid Job ID: ${newState.jobId}`);
}

if (!Object.values(ImportUrlStatus).includes(newState.status)) {
throw new Error(`Invalid Import URL status: ${newState.status}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe('ImportUrl Model tests', () => {
it('throws an error if status is invalid', () => {
expect(() => createImportUrl({ ...validImportUrlData, status: 'invalid' })).to.throw('Invalid Import URL status: invalid');
});

it('throws an error if jobId is not a valid string', () => {
expect(() => createImportUrl({ ...validImportUrlData, jobId: null })).to.throw('Invalid Job ID: null');
});
});
describe('Import URL Functionality Tests', () => {
let importUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('Import Url Tests', () => {
const mockImportUrl = {
id: 'test-id',
status: 'RUNNING',
jobId: 'test-job-id',
url: 'https://www.test.com',
};
await exportedFunctions.createNewImportUrl(mockImportUrl);
Expand All @@ -80,6 +81,7 @@ describe('Import Url Tests', () => {
it('should update an existing importUrl with the correct status', async () => {
const mockImportUrl = {
id: 'test-id',
jobId: 'test-job-id',
status: 'RUNNING',
url: 'https://www.test.com',
};
Expand All @@ -97,6 +99,7 @@ describe('Import Url Tests', () => {
it('should throw an error when the importUrl does not exist', async () => {
const mockImportUrl = {
id: 'test-id',
jobId: 'test-job-id',
status: 'RUNNING',
url: 'https://www.test.com',
};
Expand Down

0 comments on commit 0d16294

Please sign in to comment.