Skip to content

Commit

Permalink
Merge branch 'develop' into readme404bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rishikunnath2747 authored Jan 16, 2025
2 parents f60f79b + 2f65938 commit 125e415
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/sdm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ module.exports = class SDMAttachmentsService extends (

async checkRepositoryType(req) {
const { repositoryId } = getConfigurations();
let subdomain = cds.context.user?.tokenInfo?.getPayload()?.ext_attr?.zdn;
//check if repository is versionable
let repotype = cache.get(repositoryId)
let repotype = cache.get(repositoryId+"_"+subdomain);
let isVersioned;
if (repotype == undefined) {
const token = await getClientCredentialsToken(this.creds);
Expand Down
5 changes: 3 additions & 2 deletions lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ function isRepositoryVersioned(repoInfo, repositoryId) {
}

function saveRepoToCache(repositoryId, type) {
const repoType = cache.get(repositoryId);
let subdomain = cds.context.user?.tokenInfo?.getPayload()?.ext_attr?.zdn;
const repoType = cache.get(repositoryId+"_"+subdomain);
if (repoType === undefined) {
cache.set(repositoryId, type, 60 * 60 * 24 * 60);
cache.set((repositoryId+"_"+subdomain), type, 60 * 60 * 24 * 60);
}
}

Expand Down
75 changes: 72 additions & 3 deletions test/lib/sdm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ describe("SDMAttachmentsService", () => {
},
},
};

cds = require("@sap/cds/lib");
cds.context = {
user: {
tokenInfo: {
getPayload: jest.fn(() => ({
ext_attr: {
zdn: 'subdomain' // simulate the subdomain extraction
}
})),
},
},
};
const attachments = ["attachment1", "attachment2"];
const keys = ["key1", "key2"];
const response = { url: "mockUrl" };
Expand Down Expand Up @@ -132,6 +143,18 @@ describe("SDMAttachmentsService", () => {
},
},
};
cds = require("@sap/cds/lib");
cds.context = {
user: {
tokenInfo: {
getPayload: jest.fn(() => ({
ext_attr: {
zdn: 'subdomain' // simulate the subdomain extraction
}
})),
},
},
};
const attachments = ["attachment1", "attachment2"];
const keys = ["key1", "key2"];
const response = { url: "mockUrl" };
Expand Down Expand Up @@ -169,6 +192,18 @@ describe("SDMAttachmentsService", () => {
},
reject: jest.fn(),
};
cds = require("@sap/cds/lib");
cds.context = {
user: {
tokenInfo: {
getPayload: jest.fn(() => ({
ext_attr: {
zdn: 'subdomain' // simulate the subdomain extraction
}
})),
},
},
};
const attachments = ["attachment1", "attachment2"];
const keys = ["key1", "key2"];
isRepositoryVersioned.mockResolvedValue(true);
Expand All @@ -189,6 +224,18 @@ describe("SDMAttachmentsService", () => {
},
reject: jest.fn(),
};
cds = require("@sap/cds/lib");
cds.context = {
user: {
tokenInfo: {
getPayload: jest.fn(() => ({
ext_attr: {
zdn: 'subdomain' // simulate the subdomain extraction
}
})),
},
},
};
const attachments = ["attachment1", "attachment2"];
const keys = ["key1", "key2"];
isRepositoryVersioned.mockResolvedValue(true);
Expand All @@ -208,7 +255,18 @@ describe("SDMAttachmentsService", () => {
},
},
};

cds = require("@sap/cds/lib");
cds.context = {
user: {
tokenInfo: {
getPayload: jest.fn(() => ({
ext_attr: {
zdn: 'subdomain' // simulate the subdomain extraction
}
})),
},
},
};
const attachments = ["attachment1", "attachment2"];
const keys = ["key1", "key2"];
const response = { url: "mockUrl" };
Expand Down Expand Up @@ -267,14 +325,25 @@ describe("SDMAttachmentsService", () => {
info: jest.fn(),
warn: jest.fn()
};

cds = require("@sap/cds/lib");
cds.model.definitions[mockReq.query.target.name + ".attachments"] = {
keys: {
up_: {
keys: [{ ref: ["attachment"] }],
},
},
};
cds.context = {
user: {
tokenInfo: {
getPayload: jest.fn(() => ({
ext_attr: {
zdn: 'subdomain' // simulate the subdomain extraction
}
})),
},
},
};
NodeCache.prototype.get.mockImplementation(() => undefined);
getConfigurations.mockResolvedValueOnce({repositoryId: "123"});
getRepositoryInfo.mockResolvedValueOnce(repoInfo);
Expand Down
11 changes: 6 additions & 5 deletions test/lib/util/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ describe("util", () => {
}
const isVersioned = isRepositoryVersioned(mockRepoInfo, "mockedRepoId");
expect(isVersioned).toBe(true);
expect(NodeCache.prototype.get).toBeCalledWith("mockedRepoId");
expect(NodeCache.prototype.set).toBeCalledWith("mockedRepoId", "versioned", 60 * 60 * 24 * 60);
expect(NodeCache.prototype.get).toBeCalledWith("mockedRepoId_subdomain");
expect(NodeCache.prototype.set).toBeCalledWith("mockedRepoId_subdomain", "versioned", 60 * 60 * 24 * 60);
});

it("should not set cache and return true when repotype is pwconly", () => {
Expand All @@ -293,7 +293,7 @@ describe("util", () => {
}
const isVersioned = isRepositoryVersioned(mockRepoInfo, "mockedRepoId");
expect(isVersioned).toBe(true);
expect(NodeCache.prototype.get).toBeCalledWith("mockedRepoId");
expect(NodeCache.prototype.get).toBeCalledWith("mockedRepoId_subdomain");
expect(NodeCache.prototype.set).not.toHaveBeenCalled();
});

Expand All @@ -308,10 +308,11 @@ describe("util", () => {
}
}
}

const isVersioned = isRepositoryVersioned(mockRepoInfo, "mockedRepoId");
expect(isVersioned).toBe(false);
expect(NodeCache.prototype.get).toBeCalledWith("mockedRepoId");
expect(NodeCache.prototype.set).toBeCalledWith("mockedRepoId", "non-versioned", 60 * 60 * 24 * 60);
expect(NodeCache.prototype.get).toBeCalledWith("mockedRepoId_subdomain");
expect(NodeCache.prototype.set).toBeCalledWith("mockedRepoId_subdomain", "non-versioned", 60 * 60 * 24 * 60);
});
})

Expand Down

0 comments on commit 125e415

Please sign in to comment.