-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added unit test for organizations
- Loading branch information
1 parent
fdada9d
commit 60bee1d
Showing
8 changed files
with
195 additions
and
14 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,2 +1,4 @@ | ||
node_modules/ | ||
.mesh/ | ||
.mesh/ | ||
.env | ||
.vscode |
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,13 +1,16 @@ | ||
import { getMeshSDK, Sdk } from '../.mesh'; | ||
import { Organization } from './organization/organization'; | ||
|
||
export class Gateway { | ||
private sdk: Sdk; | ||
public organization: Organization; | ||
|
||
constructor({ apiKey, token }: { apiKey: string; token: string }) { | ||
if (!apiKey && !token) throw new Error('No token found'); | ||
this.sdk = getMeshSDK({ | ||
apiKey, | ||
token, | ||
}); | ||
this.organization = new Organization(this.sdk); | ||
} | ||
} |
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,7 @@ | ||
export const errorHandler = (error: any): string => { | ||
if (typeof error === 'object' && error !== null && 'message' in error) { | ||
return error.message; | ||
} else { | ||
return 'Something went wrong!'; | ||
} | ||
}; |
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,86 @@ | ||
import dotenv from 'dotenv'; | ||
import { Gateway } from '../src/Gateway'; | ||
import { | ||
OrganizationIdentifierType, | ||
OrganizationRole, | ||
UserIdentifierType, | ||
} from '../src/types'; | ||
dotenv.config(); | ||
const DEFAULT_TIMEOUT = 10000; | ||
|
||
let api: Gateway; | ||
|
||
beforeAll(() => { | ||
api = new Gateway({ | ||
apiKey: process.env.API_KEY!, | ||
token: process.env.BEARER_TOKEN!, | ||
}); | ||
}); | ||
|
||
describe('ORGANIZATION SERVICE TESTING', () => { | ||
it( | ||
'organization crud', | ||
async () => { | ||
let obj = { | ||
username: 'test_for_sdk_2', | ||
name: 'test org sdk 2', | ||
description: 'test organization', | ||
}; | ||
const { createOrganization } = | ||
await api.organization.createOrganization(obj); | ||
const { organization } = await api.organization.getOrganization( | ||
OrganizationIdentifierType.ORG_ID, | ||
createOrganization.id, | ||
); | ||
expect(organization?.id).toEqual(createOrganization.id); | ||
let updatedOrgObj = { | ||
description: 'changed description for organization', | ||
id: createOrganization.id, | ||
}; | ||
const { updateOrganization } = | ||
await api.organization.updateOrganization(updatedOrgObj); | ||
expect(updateOrganization.description).toEqual(updatedOrgObj.description); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
|
||
it( | ||
'member crud organization', | ||
async () => { | ||
let addMemberObj = { | ||
organization: { | ||
type: OrganizationIdentifierType.ORG_ID, | ||
value: process.env.ORGAINZATION_ID!, | ||
}, | ||
user: { type: UserIdentifierType.GATEWAY_ID, value: 'testing_sdk' }, | ||
}; | ||
let changeMemberRoleObj = { | ||
...addMemberObj, | ||
role: OrganizationRole.Admin, | ||
}; | ||
const { addMemberToOrganization } = | ||
await api.organization.addMemberToOrganization(addMemberObj); | ||
expect(addMemberToOrganization).toBeDefined(); | ||
const { changeMemberRole } = | ||
await api.organization.changeMemberRole(changeMemberRoleObj); | ||
expect(changeMemberRole).toBeDefined(); | ||
const { removeMemberFromOrganization } = | ||
await api.organization.removeMemberFromOrganization(addMemberObj); | ||
expect(removeMemberFromOrganization).toBeDefined(); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
|
||
it( | ||
'organizations', | ||
async () => { | ||
const { organizations } = await api.organization.getOrganizations({ | ||
filter: { verified: false }, | ||
skip: 0, | ||
take: 10, | ||
}); | ||
expect(organizations.length).toBeGreaterThanOrEqual(0); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
}); |