kat-kan / kawqa-gad-playwright

4 stars 1 forks source link

[Issue 65] Create user using faker #128

Open Slawomir-DKl opened 2 weeks ago

Slawomir-DKl commented 2 weeks ago

Resolves #65

Scope of changes:

  1. I added logic for creating a custom user (with fake data), logging in, and using the token for this user in tests
  2. I created a sample test using the new logic

Detailed description: The new logic uses the new createUser function from the create-user.helper.ts file. The createUser function uses the new generateFakeUserData function which generates user data using faker (avatar is randomly selected from images available in GAD) The generated user data are consistent with the new UserData interface in the user.model.ts file.

Additional improvements: To ensure the user type is correctly stated, I added a new enum (UserType) and replaced all instances of regular and admin with this new enum.

How to use it:

To test as a custom user, create headers with the UserType.custom parameter, e.g.

const setHeaders = await createHeaders(UserType.custom);

In general, to explicitly state the user type for creating headers, use the new enum, e.g. instead of createHeaders('admin') now you have to use createHeaders(UserType.admin).

Faker:

First install the faker library: npm i @faker-js/faker

To use the faker, import it (I suggest importing only EN version to improve test performance):

import {faker } from '@faker-js/faker/locale/en'

Any other comments?

See the exemplary test GET quiz questions endpoint tests › Returns 200 OK with authorization to check, how it works.

Before submitting Pull Request, I've ensured that: