Skip to content

Commit

Permalink
SCRUM-136 add placeholder img & update tc
Browse files Browse the repository at this point in the history
  • Loading branch information
germainetan committed Oct 12, 2024
1 parent 50a7268 commit ee3a977
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
25 changes: 14 additions & 11 deletions backend/__tests__/services/accountsGamificationService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ describe("getGamificationData", () => {

describe("getBadges", () => {
const badges = [
{
publicUrl: "https://badges.com/placeholder.png",
},
{
publicUrl: "https://badges.com/placeholder.png",
},
{
publicUrl: "https://badges.com/badge2.png",
},
Expand All @@ -291,12 +297,15 @@ describe("getBadges", () => {

const mockData = [
{
badge: "badge1",
name: "badge1",
},
{
badge: "badge2",
}
]
name: "badge2",
},
{
name: "placeholder",
},
];

it("should return an array of badge URLs", async () => {
resultService.getNoOfCompletedUnit.mockResolvedValue(4);
Expand All @@ -305,10 +314,8 @@ describe("getBadges", () => {
const mockList = jest
.fn()
.mockResolvedValue({ data: mockData, error: null });
// supabase.storage.from.mockReturnValue({ list: mockList });

// indiv calls to get badges individually

let mockGetPublicURL = jest.fn();

for (let i = 0; i < badges.length; i++) {
Expand All @@ -324,11 +331,7 @@ describe("getBadges", () => {

const expectedResult = badges.map((badge) => badge.publicUrl);

expect(result).toEqual([
"Badge Design in Progress!",
"Badge Design in Progress!",
...expectedResult,
]);
expect(result).toEqual(expectedResult);
});

it("should return 'Badges Not Found' when there are no badges in storage", async () => {
Expand Down
12 changes: 10 additions & 2 deletions backend/dist/services/accountsGamificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ function getBadges(userID) {
if (storageBadges.length === 0) {
throw new Error("Badge Not Found");
}
const withoutBadge = Math.max(0, completedUnit - storageBadges.length);
const designed = storageBadges
.map((badge) => badge.name)
.filter((badge) => badge.includes("badge"));
const withoutBadge = Math.max(0, completedUnit - designed.length);
const minBadges = completedUnit - withoutBadge;
for (let i = 0; i < withoutBadge; i++) {
badges.push("Badge Design in Progress!");
const { data: publicUrlData } = yield supabaseConfig_1.default.storage
.from("badges")
.getPublicUrl(`placeholder.png`);
if (publicUrlData) {
badges.push(publicUrlData.publicUrl);
}
}
for (let i = minBadges; i > 0; i--) {
const { data: publicUrlData } = yield supabaseConfig_1.default.storage
Expand Down
14 changes: 12 additions & 2 deletions backend/src/services/accountsGamificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,21 @@ export async function getBadges(userID: string) {
throw new Error("Badge Not Found");
}

const withoutBadge = Math.max(0, completedUnit - storageBadges.length);
const designed = storageBadges
.map((badge) => badge.name)
.filter((badge) => badge.includes("badge"));

const withoutBadge = Math.max(0, completedUnit - designed.length);
const minBadges = completedUnit - withoutBadge;

for (let i = 0; i < withoutBadge; i++) {
badges.push("Badge Design in Progress!");
const { data: publicUrlData } = await supabase.storage
.from("badges")
.getPublicUrl(`placeholder.png`);

if (publicUrlData) {
badges.push(publicUrlData.publicUrl);
}
}

for (let i = minBadges; i > 0; i--) {
Expand Down

0 comments on commit ee3a977

Please sign in to comment.