Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
60 changes: 0 additions & 60 deletions __tests__/schema/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,37 +196,6 @@ describe('query userExperiences', () => {
expect(res.data.userExperiences.edges).toHaveLength(1);
});

it('should restrict fields for anonymous users to only allowed columns', async () => {
loggedUser = null;

const res = await client.query(USER_EXPERIENCES_QUERY, {
variables: { userId: '1' },
});

expect(res.errors).toBeFalsy();
expect(res.data.userExperiences.edges).toHaveLength(1);

const experience = res.data.userExperiences.edges[0].node;

// Allowed columns for anonymous users
expect(experience).toMatchObject({
id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
type: 'work',
title: 'Senior Software Engineer',
company: {
id: 'company-1',
name: 'Daily.dev',
},
});

// Restricted columns should be null for anonymous users
expect(experience.subtitle).toBeNull();
expect(experience.description).toBeNull();
expect(experience.startedAt).toBeNull();
expect(experience.endedAt).toBeNull();
expect(experience.createdAt).toBeNull();
});

it('should return all fields for logged-in users', async () => {
loggedUser = '1';

Expand Down Expand Up @@ -515,35 +484,6 @@ describe('query userExperienceById', () => {
});
});

it('should restrict fields for anonymous users when fetching by id', async () => {
loggedUser = null;

const res = await client.query(USER_EXPERIENCE_BY_ID_QUERY, {
variables: { id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479' },
});

expect(res.errors).toBeFalsy();

const experience = res.data.userExperienceById;

// Allowed columns for anonymous users
expect(experience).toMatchObject({
id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
type: 'work',
title: 'Senior Software Engineer',
company: {
name: 'Daily.dev',
},
});

// Restricted columns should be null for anonymous users
expect(experience.subtitle).toBeNull();
expect(experience.description).toBeNull();
expect(experience.startedAt).toBeNull();
expect(experience.endedAt).toBeNull();
expect(experience.createdAt).toBeNull();
});

it('should return experience from another user', async () => {
loggedUser = '1';

Expand Down
5 changes: 4 additions & 1 deletion src/common/schema/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const userExperienceWorkSchema = z
externalReferenceId: z.string().optional(),
employmentType: z.number().nullable().optional().default(null),
locationType: z.number().nullable().optional().default(null),
locationId: z.uuidv4().nullable().optional().default(null),
locationId: z.preprocess(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can send empty string

(val) => (val === '' ? null : val),
z.string().uuid().nullable().optional().default(null),
),
skills: z
.array(z.string().trim().normalize().nonempty().max(100))
.max(50)
Expand Down
11 changes: 0 additions & 11 deletions src/graphorm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1726,17 +1726,6 @@ const obj = new GraphORM({
from: 'DatasetLocation',
},
UserExperience: {
anonymousRestrictedColumns: [
'user',
'subtitle',
'description',
'startedAt',
'endedAt',
'location',
'locationType',
'createdAt',
'updatedAt',
],
fields: {
startedAt: {
transform: transformDate,
Expand Down
Loading