Skip to content

Commit

Permalink
Merge branch 'main' into feat(backend)/create-settings-property-in-us…
Browse files Browse the repository at this point in the history
…er-profile
  • Loading branch information
AntonioVentilii authored Nov 29, 2024
2 parents b842df3 + 28b60a5 commit b15acc2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/frontend/src/tests/lib/services/load-user-profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import { loadUserProfile } from '$lib/services/load-user-profile.services';
import { userProfileStore } from '$lib/stores/user-profile.store';
import en from '$tests/mocks/i18n.mock';
import { mockIdentity } from '$tests/mocks/identity.mock';
import { mockUserProfile } from '$tests/mocks/user-profile.mock';
import { waitFor } from '@testing-library/svelte';
import { beforeEach } from 'node:test';
import { get } from 'svelte/store';

vi.mock('$lib/api/backend.api');

const mockProfile: UserProfile = {
credentials: [],
version: [1n],
created_timestamp: 1234n,
updated_timestamp: 1234n
...mockUserProfile,
version: [1n]
};
const nullishIdentityErrorMessage = en.auth.error.no_internet_identity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { POUH_CREDENTIAL_TYPE } from '$lib/constants/credentials.constants';
import { requestPouhCredential } from '$lib/services/request-pouh-credential.services';
import { i18n } from '$lib/stores/i18n.store';
import { userProfileStore } from '$lib/stores/user-profile.store';
import { mockUserProfile } from '$tests/mocks/user-profile.mock';
import { toastsStore } from '@dfinity/gix-components';
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { Principal } from '@dfinity/principal';
Expand Down Expand Up @@ -35,12 +36,7 @@ describe('request-pouh-credential.services', () => {

const identity = Ed25519KeyIdentity.generate();

const initialUserProfile: UserProfile = {
version: [],
created_timestamp: 1234n,
updated_timestamp: 1234n,
credentials: []
};
const initialUserProfile: UserProfile = { ...mockUserProfile };

beforeEach(() => {
vi.clearAllMocks();
Expand All @@ -55,9 +51,7 @@ describe('request-pouh-credential.services', () => {
it('should request credential validate it and store it', async () => {
addUserCredentialMock.mockResolvedValueOnce({ Ok: null });
const userProfileWithCredential: UserProfile = {
version: [],
created_timestamp: 1234n,
updated_timestamp: 1234n,
...mockUserProfile,
credentials: [
{
issuer: 'pouh',
Expand Down
11 changes: 4 additions & 7 deletions src/frontend/src/tests/lib/utils/credentials.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { UserProfile } from '$declarations/backend/backend.did';
import { hasPouhCredential } from '$lib/utils/credentials.utils';
import { mockUserProfile } from '$tests/mocks/user-profile.mock';

describe('credentials utils', () => {
describe('hasPouhCredential', () => {
Expand All @@ -10,41 +11,37 @@ describe('credentials utils', () => {

it('should return true if the user has verified credential', () => {
const profile: UserProfile = {
...mockUserProfile,
credentials: [
{
issuer: 'test',
credential_type: { ProofOfUniqueness: null },
verified_date_timestamp: [123456n]
}
],
created_timestamp: 123456n,
updated_timestamp: 123456n,
version: [0n]
};
expect(hasPouhCredential(profile)).toBe(true);
});

it('should return false if the user has credential but not verified', () => {
const profile: UserProfile = {
...mockUserProfile,
credentials: [
{
issuer: 'test',
credential_type: { ProofOfUniqueness: null },
verified_date_timestamp: []
}
],
created_timestamp: 123456n,
updated_timestamp: 123456n,
version: [0n]
};
expect(hasPouhCredential(profile)).toBe(false);
});

it('should return false if the user has no credentials', () => {
const profile: UserProfile = {
credentials: [],
created_timestamp: 123456n,
updated_timestamp: 123456n,
...mockUserProfile,
version: [0n]
};
expect(hasPouhCredential(profile)).toBe(false);
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/src/tests/mocks/user-profile.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { UserProfile } from '$declarations/backend/backend.did';

export const mockUserProfile: UserProfile = {

Check failure on line 3 in src/frontend/src/tests/mocks/user-profile.mock.ts

View workflow job for this annotation

GitHub Actions / test

Property 'settings' is missing in type '{ credentials: never[]; version: []; created_timestamp: bigint; updated_timestamp: bigint; }' but required in type 'UserProfile'.
credentials: [],
version: [],
created_timestamp: 1234n,
updated_timestamp: 1234n
};

0 comments on commit b15acc2

Please sign in to comment.