Skip to content

Commit 2f04fbc

Browse files
authored
ENG-999 - add more project fields and credit issuances for projects to API (#566)
1 parent 92ee6bb commit 2f04fbc

11 files changed

+116
-6
lines changed

src/api-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
Subaccount,
1414
ImpactData,
1515
ImpactHostedPageConfig,
16-
Project,
16+
ProjectWithCreditIssuances,
1717
ProjectCategoryWithProjects,
1818
Portfolio,
1919
PortfolioWithCategoryAllocations,
@@ -519,13 +519,13 @@ export class CNaughtApiClient {
519519
* Get details for a project
520520
* @param id Id of the project whose details are to be retrieved
521521
* @param requestOptions Optional additional request options, e.g. for transforming the Request before sending
522-
* @returns Project details
522+
* @returns Project details with credit issuances
523523
*/
524524
getProjectDetails = (
525525
id: string,
526526
requestOptions?: ApiRequestOptions
527-
): Promise<Project> =>
528-
this.apiHandler.makeApiGetRequest<Project>(
527+
): Promise<ProjectWithCreditIssuances> =>
528+
this.apiHandler.makeApiGetRequest<ProjectWithCreditIssuances>(
529529
`/projects/${id}`,
530530
requestOptions
531531
);

src/models/CreditIssuance.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface CreditIssuance {
2+
vintage_year: number;
3+
total_amount: number;
4+
}

src/models/Project.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import type { ProjectDueDiligenceFigure } from './ProjectDueDiligenceFigure.js';
2+
import type { ProjectLifetime } from './ProjectLifetime.js';
3+
import type { ProjectNewsArticle } from './ProjectNewsArticle.js';
4+
import type { ProjectNotableBuyer } from './ProjectNotableBuyer.js';
5+
16
export interface Project {
27
id: string;
38
name: string;
49
type: string;
10+
activity_types?: string[];
511
developer?: string;
612
registry_name?: string;
713
registry_id?: string;
@@ -13,4 +19,16 @@ export interface Project {
1319
location_longitude?: number;
1420
primary_image_url?: string;
1521
un_sdg_goals: number[];
22+
methodology?: string;
23+
verifier?: string;
24+
permanence?: string;
25+
lifetime?: ProjectLifetime;
26+
impact_type?: string;
27+
due_diligence?: string;
28+
beyond_carbon?: string;
29+
risk_of_reversal?: string;
30+
third_party_labels?: string[];
31+
notable_buyers?: ProjectNotableBuyer[];
32+
due_diligence_figure?: ProjectDueDiligenceFigure;
33+
news_articles?: ProjectNewsArticle[];
1634
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface ProjectDueDiligenceFigure {
2+
description: string;
3+
image_url: string;
4+
image_alt_text?: string;
5+
}

src/models/ProjectLifetime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface ProjectLifetime {
2+
start_year?: number;
3+
end_year?: number;
4+
}

src/models/ProjectNewsArticle.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface ProjectNewsArticle {
2+
title: string;
3+
url: string;
4+
author: string;
5+
published_on: string;
6+
cnaught_take?: string;
7+
}

src/models/ProjectNotableBuyer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface ProjectNotableBuyer {
2+
name: string;
3+
logo_url: string;
4+
logo_alt_text?: string;
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { CreditIssuance } from './CreditIssuance.js';
2+
import type { Project } from './Project.js';
3+
4+
export interface ProjectWithCreditIssuances extends Project {
5+
credit_issuances: CreditIssuance[];
6+
}

src/models/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export * from './ImpactHostedPageConfig.js';
1818
export * from './CNaughtProblemDetails.js';
1919
export * from './quotes/index.js';
2020
export * from './Project.js';
21+
export * from './ProjectLifetime.js';
22+
export * from './ProjectNewsArticle.js';
23+
export * from './ProjectNotableBuyer.js';
24+
export * from './ProjectDueDiligenceFigure.js';
2125
export * from './ProjectAllocation.js';
2226
export * from './ProjectCategory.js';
2327
export * from './ProjectCategoryWithProjects.js';
@@ -30,3 +34,9 @@ export * from './SubaccountLogoFileOptions.js';
3034
export * from './ImpactDateFilterOptions.js';
3135
export * from './CheckoutSession.js';
3236
export * from './CheckoutSessionOptions.js';
37+
export * from './CreditIssuance.js';
38+
export * from './ProjectLifetime.js';
39+
export * from './ProjectNewsArticle.js';
40+
export * from './ProjectNotableBuyer.js';
41+
export * from './ProjectDueDiligenceFigure.js';
42+
export * from './ProjectWithCreditIssuances.js';

test/integration/test/projects.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test('get project by id', async () => {
55

66
const project = await client.getProjectDetails('I0UbDH'); // well-known project
77

8+
// Test basic fields
89
expect(project.name).toBe('Sandbox Project A');
910
expect(project.type).toBe('Reforestation');
1011
expect(project.developer).toBe('Sandbox Project Developer');
@@ -22,4 +23,31 @@ test('get project by id', async () => {
2223
'https://assets.cnaught.com/64fd900fcf6f93409fc7ff21/67466d4c5dac34242677eb4b_64cabf485b8978f04658185f_pexels-symeon-ekizoglou-2880801.webp'
2324
);
2425
expect(project.un_sdg_goals).toStrictEqual([1, 4, 6]);
25-
}, 30000);
26+
27+
// Test new fields
28+
expect(project.activity_types).toEqual(['Reforestation', 'Improved Forest Management']);
29+
expect(project.impact_type).toBe('Removal');
30+
expect(project.methodology).toBe('Verified Carbon Standard (VCS)');
31+
expect(project.verifier).toBe('Sandbox Verification Services');
32+
expect(project.permanence).toBe('100+ years');
33+
expect(project.lifetime).toEqual({
34+
start_year: 2022,
35+
end_year: 2052
36+
});
37+
38+
// Test credit issuances
39+
expect(project.credit_issuances).toBeDefined();
40+
expect(project.credit_issuances.length).toBe(3);
41+
42+
// Check specific issuances
43+
const issuances = project.credit_issuances.sort((a, b) => a.vintage_year - b.vintage_year);
44+
45+
expect(issuances[0].vintage_year).toBe(2022);
46+
expect(issuances[0].total_amount).toBe(5000);
47+
48+
expect(issuances[1].vintage_year).toBe(2023);
49+
expect(issuances[1].total_amount).toBe(7500);
50+
51+
expect(issuances[2].vintage_year).toBe(2024);
52+
expect(issuances[2].total_amount).toBe(10000);
53+
}, 30000);

test/unit/api-client.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,30 @@ describe('api-client', () => {
148148
name: 'Some project',
149149
type: 'ARR',
150150
un_sdg_goals: [],
151-
developer: 'Test Developer'
151+
developer: 'Test Developer',
152+
activity_types: ['Test Activity'],
153+
summary: 'Test Summary',
154+
description: 'Test Description',
155+
verifier: 'Test Verifier',
156+
lifetime: {
157+
start_year: 2021,
158+
end_year: 2024
159+
},
160+
impact_type: 'Avoided Emissions',
161+
beyond_carbon: 'Test Beyond Carbon',
162+
due_diligence: 'Test Due Diligence',
163+
location_name: 'Test Location',
164+
methodology: 'Test Methodology',
165+
permanence: 'Test Permanence',
166+
news_articles: [
167+
{
168+
title: 'Test title',
169+
url: 'https://example.com',
170+
author: 'Test Author',
171+
published_on: '2022-08-05T24:00:00.29Z',
172+
cnaught_take: 'Our take'
173+
}
174+
]
152175
};
153176

154177
const projectCategoryId = 'project-category-id';

0 commit comments

Comments
 (0)