forked from Giveth/impact-graph
-
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.
Merge pull request #24 from GeneralMagicio/project-creation
Integrated project creation with abc
- Loading branch information
Showing
15 changed files
with
591 additions
and
281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// a method the get objects from mongodb api read from config DONATION_SAVE_BACKUP_API_URL with sercret read from DONATION_SAVE_BACKUP_API_SECRET, | ||
// it must filter objects by those doesn't have `imported` field with true value | ||
// also must support pagination | ||
|
||
import axios from 'axios'; | ||
import { logger } from '../../utils/logger'; | ||
import config from '../../config'; | ||
import { IAbcLauncher } from './AbcLauncherInterface'; | ||
import { Abc } from '../../entities/project'; | ||
|
||
const ABC_LAUNCH_API_URL = config.get('ABC_LAUNCH_API_URL') as string; | ||
const ABC_LAUNCH_API_SECRET = config.get('ABC_LAUNCH_API_SECRET') as string; | ||
const ABC_LAUNCH_DATA_SOURCE = config.get('ABC_LAUNCH_DATA_SOURCE') as string; | ||
const ABC_LAUNCH_COLLECTION = config.get('ABC_LAUNCH_COLLECTION') || 'project'; | ||
const ABC_LAUNCH_DATABASE = config.get('ABC_LAUNCH_DATABASE') || 'abc-launcher'; | ||
|
||
// add '/' if doesn't exist at the | ||
const baseUrl = ABC_LAUNCH_API_URL.endsWith('/') | ||
? ABC_LAUNCH_API_URL | ||
: `${ABC_LAUNCH_API_URL}/`; | ||
|
||
export class AbcLauncherAdapter implements IAbcLauncher { | ||
async getProjectAbcLaunchData( | ||
projectAddress: string, | ||
): Promise<Abc | undefined> { | ||
try { | ||
const result = await axios.post( | ||
`${baseUrl}find`, | ||
{ | ||
collection: ABC_LAUNCH_COLLECTION, | ||
database: ABC_LAUNCH_DATABASE, | ||
dataSource: ABC_LAUNCH_DATA_SOURCE, | ||
filter: { | ||
projectAddress: projectAddress.toLocaleLowerCase(), | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
'api-key': ABC_LAUNCH_API_SECRET, | ||
'Content-Type': 'application/json', | ||
'Access-Control-Request-Headers': '*', | ||
}, | ||
}, | ||
); | ||
|
||
if (result.status !== 200) { | ||
logger.error('getNotImportedDonationsFromBackup error', result.data); | ||
throw new Error( | ||
'getNotImportedDonationsFromBackup error, status: ' + result.status, | ||
); | ||
} | ||
const data = result.data.documents[0]; | ||
if (!data) return undefined; | ||
return { | ||
tokenTicker: data.tokenTicker, | ||
tokenName: data.tokenName, | ||
icon: data.iconHash, | ||
orchestratorAddress: data.orchestratorAddress, | ||
issuanceTokenAddress: data.issuanceTokenAddress, | ||
projectAddress: data.projectAddress, | ||
}; | ||
} catch (e) { | ||
logger.error('getNotImportedDonationsFromBackup error', e); | ||
throw e; | ||
} | ||
} | ||
} |
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,34 @@ | ||
import { Abc } from '../../entities/project'; | ||
import { IAbcLauncher } from './AbcLauncherInterface'; | ||
|
||
export class AbcLauncherAdapterMock implements IAbcLauncher { | ||
private _nextData: Abc; | ||
|
||
getDefaultData(): Abc { | ||
return { | ||
tokenTicker: 'MOCK', | ||
tokenName: 'Mock Token Name', | ||
icon: 'moch_icon_hash', | ||
orchestratorAddress: 'mock_address', | ||
issuanceTokenAddress: 'mock_issue_address', | ||
projectAddress: 'mock_project_address', | ||
}; | ||
} | ||
|
||
setNextData(data: Abc) { | ||
this._nextData = data; | ||
} | ||
|
||
constructor() { | ||
this._nextData = this.getDefaultData(); | ||
} | ||
|
||
async getProjectAbcLaunchData(projectAddress: string) { | ||
const data = this._nextData; | ||
this._nextData = this.getDefaultData(); | ||
return { | ||
...data, | ||
projectAddress, | ||
}; | ||
} | ||
} |
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,5 @@ | ||
import { Abc } from '../../entities/project'; | ||
|
||
export interface IAbcLauncher { | ||
getProjectAbcLaunchData(projectAddress: string): Promise<Abc | undefined>; | ||
} |
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,85 @@ | ||
import axios from 'axios'; | ||
import { assert, expect } from 'chai'; | ||
import { | ||
generateRandomEtheriumAddress, | ||
generateTestAccessToken, | ||
graphqlUrl, | ||
saveUserDirectlyToDb, | ||
} from '../../test/testUtils'; | ||
import { User } from '../entities/user'; | ||
import { createProjectQuery } from '../../test/graphqlQueries'; | ||
import { | ||
CreateProjectInput, | ||
ProjectTeamMemberInput, | ||
} from './types/project-input'; | ||
import { getAbcLauncherAdapter } from '../adapters/adaptersFactory'; | ||
|
||
describe('ProjectCreate test', createProjectTestCases); | ||
|
||
function createProjectTestCases() { | ||
let user: User; | ||
let accessToken: string; | ||
|
||
beforeEach(async () => { | ||
user = await saveUserDirectlyToDb(generateRandomEtheriumAddress()); | ||
accessToken = await generateTestAccessToken(user.id); | ||
}); | ||
|
||
it('should create project with team members successfully', async () => { | ||
assert.isOk(user); | ||
assert.isOk(accessToken); | ||
|
||
const teamMembers: ProjectTeamMemberInput[] = [ | ||
{ | ||
name: 'John Doe', | ||
image: 'https://example.com/john-doe.jpg', | ||
twitter: 'https://twitter.com/johndoe', | ||
linkedin: 'https://linkedin.com/johndoe', | ||
farcaster: 'https://farcaster.com/johndoe', | ||
}, | ||
{ | ||
name: 'Jane Doe', | ||
image: 'https://example.com/jane-doe.jpg', | ||
twitter: 'https://twitter.com/janedoe', | ||
linkedin: 'https://linkedin.com/janedoe', | ||
farcaster: 'https://farcaster.com/janedoe', | ||
}, | ||
]; | ||
|
||
const projectAddress = generateRandomEtheriumAddress(); | ||
const createProjectInput: CreateProjectInput = { | ||
title: 'Test Create Project 1', | ||
adminUserId: user.id, | ||
description: 'Test Project Description', | ||
categories: [], | ||
image: 'https://example.com/test-project.jpg', | ||
teaser: 'https://example.com/test-project-teaser.jpg', | ||
impactLocation: 'Test Impact Location', | ||
isDraft: false, | ||
teamMembers, | ||
address: projectAddress, | ||
}; | ||
|
||
const result = await axios.post( | ||
graphqlUrl, | ||
{ | ||
query: createProjectQuery, | ||
variables: { | ||
project: createProjectInput, | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}, | ||
); | ||
|
||
const project = result.data.data.createProject; | ||
assert.isOk(project); | ||
expect(project.teamMembers).to.deep.equal(teamMembers); | ||
const expectedAbc = | ||
await getAbcLauncherAdapter().getProjectAbcLaunchData(projectAddress); | ||
expect(project.abc).to.deep.equal(expectedAbc); | ||
}); | ||
} |
Oops, something went wrong.