Skip to content

Commit

Permalink
feat(test): added for users
Browse files Browse the repository at this point in the history
  • Loading branch information
R11manish committed Jan 18, 2024
1 parent e44067f commit 3520570
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { getMeshSDK } from '../.mesh';
import { UserMockService } from '../__mocks__/user.mock';
import { UserIdentifierType } from '../src/types';
import { User } from '../src/user/user';
import { userStub, walletStub } from './stubs/user.stub';

let user: User;

beforeAll(() => {
user = new User(getMeshSDK());
});

afterAll(() => {
jest.clearAllMocks();
});

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

const { me } = await user.me();

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: userStub().gatewayId!,
});

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

it('my pdas count', async () => {
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('my financial transactions', async () => {
// const { myDataRequestTemplatesCountMock } = UserMockService(user);

// const count = await user.myFinancialTransactions();

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

it('my financial transactions count', async () => {
const { myFinancialTransactionsCountMock } = UserMockService(user);

const count = await user.myFinancialTransactionsCount();

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

// it('my transactions', async () => {
// const { myDataRequestTemplatesCountMock } = UserMockService(user);

// const count = await user.myTransactions();

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

it('my wallet', async () => {
const { mywalletMock } = UserMockService(user);

const { myWallet } = await user.myWallet();

expect(myWallet.balance).toBe(walletStub().balance);
expect(mywalletMock).toHaveBeenCalled();
});

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

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

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

const { updateMyProfilePicture } = await user.updateMyProfilePicture(
userStub().profilePicture!,
);

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

0 comments on commit 3520570

Please sign in to comment.