Skip to content

Commit

Permalink
Merge pull request #12 from Gateway-DAO/feat/implement-mock
Browse files Browse the repository at this point in the history
Feat/implement mock and stubs
  • Loading branch information
Siddharth9890 authored Dec 15, 2023
2 parents fa962e5 + a18da22 commit a552766
Show file tree
Hide file tree
Showing 29 changed files with 6,334 additions and 2,368 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jest.config.js
test/*
.mesh/*
.mesh/*
__mocks__/*
dist/*
7 changes: 2 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
run: pnpm lint
- name: Build Graphql queries
run: pnpm mesh build
- name: Format code
run: pnpm format
- name: Test project
run: pnpm test
env:
DATAMODEL_ID: ${{ secrets.DATAMODEL_ID }}
BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }}
API_KEY: ${{ secrets.API_KEY }}
ORGAINZATION_ID: ${{ secrets.ORGAINZATION_ID }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules/
.mesh/
.vscode/
.env
build/
dist/
2 changes: 1 addition & 1 deletion .meshrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ customFetch: ./custom-fetch.ts

sdk:
generateOperations:
selectionSetDepth: 2
selectionSetDepth: 2
23 changes: 23 additions & 0 deletions __mocks__/auth.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Auth } from '../src/auth/auth';
import { authStub } from '../test/stubs/auth.stub';
import { pdaStub } from '../test/stubs/pda.stub';

export const AuthMockService = (auth: Auth) => ({
checkUsernameAvailabilityMock: jest
.spyOn(auth.sdk, 'checkUsernameAvailability_query')
.mockResolvedValue({
checkUsernameAvailability: true,
}),
addEmailMock: jest.spyOn(auth.sdk, 'addEmail_mutation').mockResolvedValue({
addEmail: authStub(),
}),
addWalletMock: jest
.spyOn(auth.sdk, 'addWallet_mutation')
.mockResolvedValue({ addWallet: authStub() }),
getPDAMock: jest.spyOn(auth.sdk, 'PDA_query').mockResolvedValue({
PDA: pdaStub(),
}),
createWalletNonceMock: jest
.spyOn(auth.sdk, 'createWalletNonce_mutation')
.mockResolvedValue({ createWalletNonce: authStub() }),
});
25 changes: 25 additions & 0 deletions __mocks__/dataRequestTemplate.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DataRequestTemplate } from '../src/dataRequestsTemplate/dataRequestsTemplate';
import { dataRequestTemplateStub } from '../test/stubs/dataRequestTemplate.stub';

export const dataRequestTemplateMockService = (
dataRequestTemplate: DataRequestTemplate,
) => ({
createDataRequestTemplateMock: jest
.spyOn(dataRequestTemplate.sdk, 'createDataRequestTemplate_mutation')
.mockResolvedValue({
createDataRequestTemplate: dataRequestTemplateStub(),
}),
getDataRequestTemplateMock: jest
.spyOn(dataRequestTemplate.sdk, 'dataRequestTemplate_query')
.mockResolvedValue({
dataRequestTemplate: dataRequestTemplateStub(),
}),
getDataRequestTemplatesMock: jest
.spyOn(dataRequestTemplate.sdk, 'dataRequestTemplates_query')
.mockResolvedValue({ dataRequestTemplates: [dataRequestTemplateStub()] }),
getDataRequestsTemplateCount: jest
.spyOn(dataRequestTemplate.sdk, 'dataRequestTemplatesCount_query')
.mockResolvedValue({
dataRequestTemplatesCount: 10,
}),
});
49 changes: 49 additions & 0 deletions __mocks__/organization.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Organization } from '../src/organization/organization';
import { OrganizationRole } from '../src/types';
import {
memberOrganizationStub,
organizationStub,
} from '../test/stubs/organization.stub';
import { userStub } from '../test/stubs/user.stub';

export const OrganizationMockService = (organization: Organization) => ({
createOrganizationMock: jest
.spyOn(organization.sdk, 'createOrganization_mutation')
.mockResolvedValue({
createOrganization: organizationStub(),
}),
getOrganizationMock: jest
.spyOn(organization.sdk, 'organization_query')
.mockResolvedValue({
organization: organizationStub(),
}),
updateOrganizationMock: jest
.spyOn(organization.sdk, 'updateOrganization_mutation')
.mockResolvedValue({
updateOrganization: organizationStub({
description: 'updated description',
}),
}),
getOrganizationsMock: jest
.spyOn(organization.sdk, 'organizations_query')
.mockResolvedValue({
organizations: [organizationStub()],
}),
addMemberToOrganizationMock: jest
.spyOn(organization.sdk, 'addMemberToOrganization_mutation')
.mockResolvedValue({
addMemberToOrganization: memberOrganizationStub(),
}),
changeMemberRoleMock: jest
.spyOn(organization.sdk, 'changeMemberRole_mutation')
.mockResolvedValue({
changeMemberRole: memberOrganizationStub({
role: OrganizationRole.Admin,
}),
}),
removeMemberFromOrganizationMock: jest
.spyOn(organization.sdk, 'removeMemberFromOrganization_mutation')
.mockResolvedValue({
removeMemberFromOrganization: true,
}),
});
25 changes: 25 additions & 0 deletions __mocks__/pda.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PDA } from '../src/pda/pda';
import { pdaStub } from '../test/stubs/pda.stub';

export const PDAMockService = (pda: PDA) => ({
createPDAMock: jest.spyOn(pda.sdk, 'createPDA_mutation').mockResolvedValue({
createPDA: pdaStub(),
}),
changePDAStatusMock: jest
.spyOn(pda.sdk, 'changePDAStatus_mutation')
.mockResolvedValue({
changePDAStatus: pdaStub({ status: 'Suspended' }),
}),
pdaCountMock: jest
.spyOn(pda.sdk, 'PDACount_query')
.mockResolvedValue({ PDACount: 10 }),
getPDAMock: jest.spyOn(pda.sdk, 'PDA_query').mockResolvedValue({
PDA: pdaStub(),
}),
pdasMock: jest
.spyOn(pda.sdk, 'PDAs_query')
.mockResolvedValue({ PDAs: [pdaStub()] }),
issuedPDAMock: jest
.spyOn(pda.sdk, 'issuedPDAsCount_query')
.mockResolvedValue({ issuedPDAsCount: 10 }),
});
42 changes: 42 additions & 0 deletions __mocks__/user.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Organization } from '../src/organization/organization';
import { User } from '../src/user/user';
import { organizationStub } from '../test/stubs/organization.stub';
import { userStub } from '../test/stubs/user.stub';

export const UserMockService = (user: User) => ({
meMock: jest.spyOn(user.sdk, 'me_query').mockResolvedValue({
me: userStub(),
}),
getSingleUserMock: jest.spyOn(user.sdk, 'user_query').mockResolvedValue({
user: userStub(),
}),
myPDACountMock: jest.spyOn(user.sdk, 'myPDACount_query').mockResolvedValue({
myPDACount: 10,
}),
myPDAsMock: jest.spyOn(user.sdk, 'myPDAs_query').mockResolvedValue({
myPDAs: userStub().issuedPDAs,
}),
myDataModelsCountMock: jest
.spyOn(user.sdk, 'dataModelsCount_query')
.mockResolvedValue({
dataModelsCount: 10,
}),
myDataRequestTemplatesCountMock: jest
.spyOn(user.sdk, 'myDataRequestTemplatesCount_query')
.mockResolvedValue({
myDataRequestTemplatesCount: 10,
}),
updateUserMock: jest
.spyOn(user.sdk, 'updateUser_mutation')
.mockResolvedValue({
updateUser: userStub({ displayName: 'testuser02' }),
}),
updateMyProfilePictureMock: jest
.spyOn(user.sdk, 'updateMyProfilePicture_mutation')
.mockResolvedValue({
updateMyProfilePicture: userStub({
profilePicture:
'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png',
}).profilePicture,
}),
});
51 changes: 28 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
{
"name": "javascript-sdk",
"version": "1.0.0",
"name": "@Gateway-dao/js-sdk",
"version": "0.0.0",
"description": "",
"main": "index.js",
"main": "dist/src/Gateway.js",
"types": "dist/src/types.d.ts",
"scripts": {
"test": "jest",
"dev": "ts-node src/index.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
"format": "prettier --write .",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"license": "MIT",
"dependencies": {
"@graphql-mesh/cli": "^0.87.14",
"@graphql-mesh/graphql": "^0.95.7",
"@graphql-mesh/runtime": "^0.96.11",
"@graphql-mesh/transform-filter-schema": "^0.96.0",
"@types/node": "^20.8.4",
"@whatwg-node/fetch": "^0.9.13",
"@graphql-mesh/cli": "^0.87.16",
"@graphql-mesh/graphql": "^0.95.8",
"@graphql-mesh/runtime": "^0.96.13",
"@graphql-mesh/transform-filter-schema": "^0.96.2",
"@solana/web3.js": "^1.87.6",
"@whatwg-node/fetch": "^0.9.14",
"ethers": "^5.7.2",
"graphql": "^16.8.1"
},
"devDependencies": {
"@types/jest": "^29.5.7",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"dotenv": "^16.3.1",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard-with-typescript": "^39.1.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"prettier": "^3.1.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.3.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Gateway-DAO/gateway-js-sdk.git"
}
}
Loading

0 comments on commit a552766

Please sign in to comment.