forked from Giveth/impact-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrated project creation with abc #24
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
410938b
Integrated project creation with abc
aminlatifi f7f7cda
Merge branch 'staging' into project-creation
aminlatifi a116299
Added QAcc related env to example.env
aminlatifi 7285c0e
Removed unrelated comments
aminlatifi c91105f
Added abc launcher env to test.env
aminlatifi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need this method?
We can not directly use just getDefaultData body inside of getPorjectAbcLunchData?
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.
I put it just to set the expected next output.