forked from sismo-core/app-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ZkBadgeAppConfig (sismo-core#154)
--------- Co-authored-by: leo Sayous <[email protected]>
- Loading branch information
1 parent
f009c9d
commit f12e8f4
Showing
79 changed files
with
23,242 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
{ | ||
"tabWidth": 2, | ||
"printWidth": 100 | ||
} | ||
"printWidth": 100, | ||
|
||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"tabWidth": 2, | ||
"printWidth": 100 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import ServiceFactory from "@/src/services/service-factory/service-factory"; | ||
import { GET } from "../../image/[tokenId]/route"; | ||
import { spaceMock1, spaceMock2 } from "@/src/services/spaces-service/tests/spaces-mock"; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
|
||
describe('GET /api/zk-badge/image/[tokenId]', () => { | ||
|
||
beforeEach(() => { | ||
let spacesService = ServiceFactory.getSpacesService(); | ||
const configs = [ | ||
spaceMock1, | ||
spaceMock2 | ||
] | ||
spacesService.updateConfigs(configs); | ||
}) | ||
|
||
afterEach(() => { | ||
let configs = ServiceFactory.getSpaceConfigs(); | ||
let spacesService = ServiceFactory.getSpacesService(); | ||
spacesService.updateConfigs(configs); | ||
jest.clearAllMocks(); | ||
}) | ||
|
||
it('should return an error response if no badge is found', async () => { | ||
const params = { tokenId: "1234" }; | ||
const response = await GET(null, { params }); | ||
const data = await response.json(); | ||
expect(data).toEqual({ error: 'No badge found for tokenId: 1234' }); | ||
}); | ||
|
||
it('should return an error response if no badge image is found', async () => { | ||
const params = { tokenId: "40000001" }; | ||
const response = await GET(null, { params }); | ||
const data = await response.json(); | ||
expect(data).toEqual({ error: 'No badge image found for tokenId: 40000001' }); | ||
}); | ||
|
||
it('should return an image response if a badge is found', async () => { | ||
jest.spyOn(fs, 'readFileSync'); | ||
|
||
const params = { tokenId: "40000001" }; | ||
const dummyImageBuffer = Buffer.from([0, 1, 2, 3, 4, 5]); | ||
const imagePath = path.join(process.cwd(), '/space-config/space/images/image.png'); | ||
|
||
(fs.readFileSync as jest.Mock).mockImplementation((path) => { | ||
if (path === imagePath) { | ||
return dummyImageBuffer; | ||
} | ||
}); | ||
|
||
const response = await GET(null, { params }); | ||
|
||
const reader = response.body.getReader(); | ||
const result = await reader.read(); | ||
|
||
const data = Buffer.from(result.value); | ||
|
||
expect(Buffer.compare(data, dummyImageBuffer)).toEqual(0); | ||
expect(response.status).toEqual(200); | ||
expect(response.headers.get('Content-Type')).toEqual('image/jpeg'); | ||
}); | ||
}); |
Oops, something went wrong.