-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add tests for /projects/:id (failing) * fix #1607 and pass tests
- Loading branch information
1 parent
26b6ce8
commit 21540dc
Showing
5 changed files
with
214 additions
and
5 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
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,90 @@ | ||
import { | ||
aCarbonCredit, | ||
aCarbonPool, | ||
aCarbonPoolCreditBalance, | ||
aCarbonProject, | ||
} from "../../src/.generated/mocks/digitalCarbon.mocks"; | ||
import { POOL_INFO } from "../../src/routes/projects/get.constants"; | ||
|
||
const TCO2_VCS_981_2017 = "0xeaa9938076748d7edd4df0721b3e3fe4077349d3"; | ||
const C3T_VCS_981_2017 = "0x7dbeebf8c2356ff8c53e41928c9575054a6f331b"; | ||
|
||
const uboPool = aCarbonPool({ | ||
id: POOL_INFO.nbo.poolAddress, | ||
decimals: 18, | ||
name: "Universal Basic Offset", | ||
supply: "21202280666164910248664", | ||
}); | ||
const nboPool = aCarbonPool({ | ||
id: POOL_INFO.nbo.poolAddress, | ||
decimals: 18, | ||
name: "Nature Based Offset", | ||
supply: "31202280666164910248664", | ||
}); | ||
const nctPool = aCarbonPool({ | ||
id: POOL_INFO.nct.poolAddress, | ||
name: "Toucan Protocol: Nature Carbon Tonne", | ||
supply: "1604659955808874505539565", | ||
decimals: 18, | ||
}); | ||
const bctPool = aCarbonPool({ | ||
id: POOL_INFO.bct.poolAddress, | ||
name: "Toucan Protocol: Base Carbon Tonne", | ||
supply: "18545844499823544157213608", | ||
decimals: 18, | ||
}); | ||
const poolBalance_NBO = aCarbonPoolCreditBalance({ | ||
balance: "26202320013669175484739", | ||
pool: nboPool, | ||
deposited: "28903000000000000000000", | ||
redeemed: "2700679986330824515261", | ||
}); | ||
const poolBalance_NCT = aCarbonPoolCreditBalance({ | ||
balance: "137168659539439210", | ||
pool: nctPool, | ||
deposited: "19048774113647802186879", | ||
redeemed: "17724636944988262747669", | ||
}); | ||
const poolBalance_BCT = aCarbonPoolCreditBalance({ | ||
balance: "0", // all redeemed and moved to TCO2 | ||
pool: bctPool, | ||
deposited: "142330703112744844598983", | ||
redeemed: "142330703112744844598983", | ||
}); | ||
const carbonCredit_C3T = aCarbonCredit({ | ||
vintage: 2017, | ||
bridged: "28903000000000000000000", | ||
retired: "2645744986330824515261", | ||
currentSupply: "26257255013669175484739", | ||
poolBalances: [poolBalance_NBO], | ||
id: C3T_VCS_981_2017, | ||
}); | ||
const carbonCredit_TCO2 = aCarbonCredit({ | ||
vintage: 2017, | ||
bridged: "73794000000000000000000", | ||
retired: "6709707416786222240581", | ||
currentSupply: "62876512583213777759419", | ||
poolBalances: [poolBalance_BCT, poolBalance_NCT], | ||
id: TCO2_VCS_981_2017, | ||
}); | ||
/** A project with two pool prices (1 empty pool) */ | ||
const carbonProject = aCarbonProject({ | ||
projectID: "VCS-981", | ||
name: "Pacajai REDD+ Project", | ||
methodologies: "VM0015", | ||
id: "VCS-981", | ||
country: "Brazil", | ||
category: "Forestry", | ||
carbonCredits: [carbonCredit_TCO2, carbonCredit_C3T], | ||
}); | ||
|
||
/** Fixtures for the polygon-bridged-carbon subgraph */ | ||
const fixtures = { | ||
carbonProject, | ||
bctPool, | ||
nctPool, | ||
uboPool, | ||
nboPool, | ||
}; | ||
|
||
export default fixtures; |
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,116 @@ | ||
import { FastifyInstance } from "fastify"; | ||
import nock from "nock"; | ||
import { GRAPH_URLS, SANITY_URLS } from "../../../../src/app.constants"; | ||
import carbonProjects from "../../../fixtures/carbonProjects"; | ||
import digitalCarbon from "../../../fixtures/digitalCarbon"; | ||
import { build } from "../../../helper"; | ||
import { DEV_URL } from "../../../test.constants"; | ||
|
||
describe("GET /projects/:id", () => { | ||
let fastify: FastifyInstance; | ||
|
||
// Setup the server | ||
beforeEach(async () => { | ||
try { | ||
fastify = await build(); | ||
} catch (e) { | ||
console.error("/projects/:id get.test.ts setup failed", e); | ||
} | ||
}); | ||
|
||
test("Returns project from CMS without prices or listings", async () => { | ||
nock(SANITY_URLS.carbonProjects) | ||
.post("") | ||
.twice() // once for each query | ||
.reply(200, { | ||
data: { | ||
allProject: [carbonProjects.project], | ||
allProjectContent: [carbonProjects.projectContent], | ||
}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].tokens).post("").reply(200, { | ||
data: {}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].digitalCarbon).post("").twice().reply(200, { | ||
data: {}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].offsets).post("").reply(200, { data: {} }); | ||
nock(GRAPH_URLS["polygon"].marketplace).post("").reply(200, { | ||
data: {}, | ||
}); | ||
const response = await fastify.inject({ | ||
method: "GET", | ||
url: `${DEV_URL}/projects/VCS-191-2008`, | ||
}); | ||
const project = await response.json(); | ||
expect(response.statusCode).toEqual(200); | ||
expect(project.key).toEqual("VCS-191"); | ||
expect(project.country).toEqual("China"); | ||
}); | ||
|
||
test("Supports ?network=polygon", async () => { | ||
nock(SANITY_URLS.carbonProjects) | ||
.post("") | ||
.twice() // once for each query | ||
.reply(200, { | ||
data: { | ||
allProject: [carbonProjects.project], | ||
allProjectContent: [carbonProjects.projectContent], | ||
}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].tokens).post("").reply(200, { | ||
data: {}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].digitalCarbon) | ||
.post("") | ||
.reply(200, { | ||
data: { | ||
carbonProjects: [digitalCarbon.carbonProject], | ||
}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].offsets).post("").reply(200, { data: {} }); | ||
nock(GRAPH_URLS["polygon"].marketplace).post("").reply(200, { | ||
data: {}, | ||
}); | ||
const response = await fastify.inject({ | ||
method: "GET", | ||
url: `${DEV_URL}/projects/VCS-191-2008?network=polygon`, | ||
}); | ||
const project = await response.json(); | ||
expect(response.statusCode).toEqual(200); | ||
expect(project.prices).toHaveLength(2); | ||
}); | ||
|
||
test("Empty network param default is polygon", async () => { | ||
nock(SANITY_URLS.carbonProjects) | ||
.post("") | ||
.twice() // once for each query | ||
.reply(200, { | ||
data: { | ||
allProject: [carbonProjects.project], | ||
allProjectContent: [carbonProjects.projectContent], | ||
}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].tokens).post("").reply(200, { | ||
data: {}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].digitalCarbon) | ||
.post("") | ||
.reply(200, { | ||
data: { | ||
carbonProjects: [digitalCarbon.carbonProject], | ||
}, | ||
}); | ||
nock(GRAPH_URLS["polygon"].offsets).post("").reply(200, { data: {} }); | ||
nock(GRAPH_URLS["polygon"].marketplace).post("").reply(200, { | ||
data: {}, | ||
}); | ||
const response = await fastify.inject({ | ||
method: "GET", | ||
url: `${DEV_URL}/projects/VCS-981-2017`, | ||
}); | ||
const project = await response.json(); | ||
expect(response.statusCode).toEqual(200); | ||
expect(project.prices).toHaveLength(2); | ||
}); | ||
}); |
21540dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
demo-integration – ./examples/nextjs-typescript-integration
demo-integration-klimadao.vercel.app
klimadao-sable.vercel.app
demo-integration-git-staging-klimadao.vercel.app
integration-demo.carbonmark.com