Skip to content

Commit

Permalink
feat: completed user mocks and stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Dec 12, 2023
1 parent 25e2a58 commit bc9fed2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 22 deletions.
33 changes: 25 additions & 8 deletions __mocks__/user.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,33 @@ export const UserMockService = (user: User) => ({
getSingleUserMock: jest.spyOn(user.sdk, 'user_query').mockResolvedValue({
user: userStub(),
}),
updateOrganizationMock: jest
.spyOn(organization.sdk, 'updateOrganization_mutation')
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({
updateOrganization: organizationStub({
description: 'updated description',
}),
updateUser: userStub({ displayName: 'testuser02' }),
}),
getOrganizationsMock: jest
.spyOn(organization.sdk, 'organizations_query')
updateMyProfilePictureMock: jest
.spyOn(user.sdk, 'updateMyProfilePicture_mutation')
.mockResolvedValue({
organizations: [organizationStub()],
updateMyProfilePicture: userStub({
profilePicture:
'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png',
}).profilePicture,
}),
});
2 changes: 1 addition & 1 deletion test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ afterAll(() => {
jest.resetAllMocks();
});

describe('auth test', () => {
describe('AUTH SERVICE TESTING', () => {
it('check username availability', async () => {
const { checkUsernameAvailabilityMock } = AuthMockService(auth);

Expand Down
2 changes: 1 addition & 1 deletion test/dataRequestsTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ afterAll(() => {
jest.resetAllMocks();
});

describe('Data Requests Template test', () => {
describe('DATA REQUESTS TEMPLATE TESTING', () => {
it('create data request template', async () => {
const { createDataRequestTemplateMock } =
dataRequestTemplateMockService(dataRequestTemplate);
Expand Down
2 changes: 1 addition & 1 deletion test/stubs/dataRequestTemplate.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const dataRequestTemplateStub = (
dataRequestsCount: 10,
description: 'test',
name: 'test',
revenueGenerated: 100,
revenueGenerated: 10,
uniqueVerifiersCount: 10,
schema: {},
dataRequests: [],
Expand Down
3 changes: 3 additions & 0 deletions test/stubs/user.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ export const userStub = (overrideUser?: Partial<User>): User => ({
roles: [],
gatewayId: 'testuser01',
email: 'testuser01@mygateway.xyz',
displayName: 'testuser02',
profilePicture:
'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png',
...overrideUser,
});
53 changes: 42 additions & 11 deletions test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getMeshSDK } from '../.mesh';
import { UserMockService } from '../__mocks__/user.mock';
import { UserIdentifierType } from '../src/types';
import { User } from '../src/user/user';
import { userStub } from './stubs/user.stub';

let user: User;

Expand All @@ -12,56 +14,85 @@ afterAll(() => {
jest.clearAllMocks();
});

describe('USER Testing', () => {
describe('USER SERVICE TESTING', () => {
it('me', async () => {
const { meMock } = UserMockService(user);

const { me } = await user.me();
expect(me.gatewayId).toEqual('sid');

expect(me.gatewayId).toEqual(userStub().gatewayId);
expect(meMock).toHaveBeenCalled();
});

it('single user', async () => {
const { getSingleUserMock } = UserMockService(user);

const res = await user.getSingleUser({
type: UserIdentifierType.GATEWAY_ID,
value: 'sid',
value: userStub().gatewayId!,
});
expect(res.user?.gatewayId).toEqual('sid');

expect(res.user?.gatewayId).toEqual(userStub().gatewayId);
expect(getSingleUserMock).toHaveBeenCalled();
});

it('my pdas count', async () => {
const count = await user.myPDACount({});
const { myPDACountMock } = UserMockService(user);

const count = await user.myPDACount();

expect(count).toBeGreaterThanOrEqual(0);
expect(myPDACountMock).toHaveBeenCalled();
});

it('my pdas', async () => {
const { myPDAsMock } = UserMockService(user);

const { myPDAs } = await user.myPDAs({
skip: 0,
take: 10,
});

expect(myPDAs.length).toBeGreaterThanOrEqual(0);
expect(myPDAsMock).toHaveBeenCalled();
});

it('my data models count', async () => {
const { myDataModelsCountMock } = UserMockService(user);

const count = await user.myDataModelsCount();

expect(count).toBeGreaterThanOrEqual(0);
expect(myDataModelsCountMock).toHaveBeenCalled();
});

it('my data requests template count', async () => {
const { myDataRequestTemplatesCountMock } = UserMockService(user);

const count = await user.myDataRequestTemplatesCount();

expect(count).toBeGreaterThanOrEqual(0);
expect(myDataRequestTemplatesCountMock).toHaveBeenCalled();
});

it('update user', async () => {
const { updateUserMock } = UserMockService(user);

const { updateUser } = await user.updateUser({
displayName: 'siddharth9890',
displayName: userStub().displayName!,
});
expect(updateUser.displayName).toEqual('siddharth9890');
expect(updateUser.displayName!).toEqual(userStub().displayName!);
expect(updateUserMock).toHaveBeenCalled();
});

it('update profile picture', async () => {
const { updateMyProfilePictureMock } = UserMockService(user);

const { updateMyProfilePicture } = await user.updateMyProfilePicture(
'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png',
);
expect(updateMyProfilePicture).toEqual(
'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png',
userStub().profilePicture!,
);

expect(updateMyProfilePicture).toEqual(userStub().profilePicture!);
expect(updateMyProfilePictureMock).toHaveBeenCalled();
});
});

0 comments on commit bc9fed2

Please sign in to comment.