Skip to content

Commit

Permalink
chore: feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
solaris007 committed Aug 23, 2024
1 parent a7d60e2 commit a8bf378
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ const validateConfiguration = (config, contentSourceType) => {
}
}
};

const validateSite = (site) => {
if (!isObject(site)) {
throw new Error('Site is required');
}

const siteConfig = site.getConfig();
if (!isObject(siteConfig?.content?.source)) {
throw new Error('Site must have a content source');
const contentSource = site.getConfig()?.content?.source;
if (!isObject(contentSource)) {
throw new Error('Site must have a valid content source');
}

const contentSourceType = siteConfig.content.source.type;
if (!SUPPORTED_CONTENT_SOURCES.has(contentSourceType)) {
throw new Error(`Unsupported content source type: ${contentSourceType}`);
if (!SUPPORTED_CONTENT_SOURCES.has(contentSource.type)) {
throw new Error(`Unsupported content source type: ${contentSource.type}`);
}
};

Expand Down Expand Up @@ -131,14 +131,10 @@ export default class ContentClient {
}

#resolveDocPath(path) {
let docPath = path;

if (path.endsWith('/')) {
docPath = `${path}index`;
}
let docPath = path.endsWith('/') ? `${path}index` : path;

if (this.contentSource.type === CONTENT_SOURCE_TYPE_ONEDRIVE) {
docPath = `${docPath}.docx`;
docPath += '.docx';
}

return docPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('ContentClient', () => {

it('throws an error if site has no content source', () => {
const invalidSite = { getConfig: () => ({ }) };
expect(() => new ContentClient(env, invalidSite, log)).to.throw('Site must have a content source');
expect(() => new ContentClient(env, invalidSite, log)).to.throw('Site must have a valid content source');
});

it('throws an error if site\'s content source type is unsupported', () => {
Expand Down

0 comments on commit a8bf378

Please sign in to comment.