Skip to content
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

feat: linked user devices #372

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.24.2",
"version": "0.25.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
26 changes: 23 additions & 3 deletions src/modules/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
BLOCK_USER_MUTATION,
UNBLOCK_USER_MUTATION,
UPDATE_EMAIL_MUTATION,
LINK_DEVICE_MUTATION,
UNLINK_DEVICE_MUTATION,
} from '../../mutations';
import {
UserInterface,
Expand All @@ -44,6 +46,7 @@ import {
SocialLoginParams,
OrderBy,
AllBlockedUsersInterface,
DeviceParams,
} from '../../types';

export class Users {
Expand All @@ -69,7 +72,7 @@ export class Users {
public async getUserData(withSocial: boolean = false): Promise<UserData> {
const response = await this.client.query({
query: !withSocial ? GET_USER_DATA_QUERY : GET_USER_SOCIAL_DATA_QUERY,
fetchPolicy: 'network-only',
fetchPolicy: 'no-cache',
});

return response.data.me;
Expand Down Expand Up @@ -329,11 +332,28 @@ export class Users {
return response.data.unBlockUser;
}

public async updateEmail(email: string): Promise<boolean > {
public async updateEmail(email: string): Promise<boolean> {
const response = await this.client.mutate({
mutation: UPDATE_EMAIL_MUTATION,
variables: { email },
});
return response.data;
}
}


public async linkDevice(input: DeviceParams): Promise<boolean> {
const response = await this.client.mutate({
mutation: LINK_DEVICE_MUTATION,
variables: { data: input },
});
return response.data.linkDevice;
}

public async unLinkDevice(input: DeviceParams): Promise<boolean> {
const response = await this.client.mutate({
mutation: UNLINK_DEVICE_MUTATION,
variables: { data: input },
});
return response.data.unLinkDevice;
}
}
12 changes: 12 additions & 0 deletions src/mutations/users.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,16 @@ export const UPDATE_EMAIL_MUTATION = gql`
mutation updateEmail($email: String!) {
updateEmail(email: $email)
}
`;

export const LINK_DEVICE_MUTATION = gql`
mutation linkDevice($data: DeviceInput!) {
linkDevice(data: $data)
}
`;

export const UNLINK_DEVICE_MUTATION = gql`
mutation unLinkDevice($data: DeviceInput!) {
unLinkDevice(data: $data)
}
`;
11 changes: 11 additions & 0 deletions src/types/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,15 @@ export interface AllBlockedUsersInterface {
data: UserInterface[];
paginatorInfo?: PaginatorInfo;
};
}

export enum SourceSite {
AndroidApp = "androidapp",
IOSApp = "iosapp",
}

export interface DeviceParams {
device_id: string;
source_site: SourceSite; // Use the enum here
source_username?: string;
}
43 changes: 42 additions & 1 deletion test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UpdateUserParams } from '../src';
import { SourceSite, UpdateUserParams } from '../src';
import { initializeClient, getClient } from './setupClient';
import dotenv from 'dotenv';

Expand Down Expand Up @@ -82,6 +82,25 @@ describe('Test the KanvasCore client', () => {
expect(updateUser.firstname).toBe('Max');
});

it('update custom field', async () => {
const client = getClient();
const userInfo = await client.users.getUserData();
const updatedUserInfo: UpdateUserParams = {
firstname: userInfo.firstname,
lastname: userInfo.lastname,
phone_number: userInfo.contact.phone_number,
cell_phone_number: userInfo.contact.cell_phone_number,
custom_fields: [{ name: 'test_custom_fields', data: '0', public: true }]
};

const updateUser = await client.users.updateUserData(
userInfo.id,
updatedUserInfo
);
expect(updateUser).toBeDefined();
expect(updateUser.firstname).toBe('Max');
});

it('gets user total following', async () => {
const client = getClient();
const userInfo = await client.users.getUserData(true);
Expand Down Expand Up @@ -129,4 +148,26 @@ describe('Test the KanvasCore client', () => {

expect(blockedUsers.blockedUsers.data).toBeDefined();
});

it('test link device', async () => {
const client = getClient();
const deviceParams = {
device_id: '123456',
source_site: SourceSite.IOSApp,
};
const linkedDevice = await client.users.linkDevice(deviceParams);

expect(linkedDevice).toBeTruthy();
});

it('test unlink device', async () => {
const client = getClient();
const deviceParams = {
device_id: '123456',
source_site: SourceSite.IOSApp,
};
const unlinkedDevice = await client.users.unLinkDevice(deviceParams);

expect(unlinkedDevice).toBeTruthy();
});
});
Loading