Skip to content

Commit

Permalink
UT's
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmiangadi11 committed Jan 13, 2025
1 parent 0b192e9 commit df3b4bb
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
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 @@ -165,6 +188,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 @@ -185,6 +220,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 @@ -204,7 +251,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 @@ -263,14 +321,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 df3b4bb

Please sign in to comment.