Skip to content

Commit

Permalink
fix(update.spec.ts, upsert.spec.ts, availability.spec.ts, customer.sp…
Browse files Browse the repository at this point in the history
…ec.ts, location.spec.ts, lookup.service.spec.ts, shipping.service.spec.ts, schedule.spec.ts, user.spec.ts): update faker method from faker.datatype.number() to faker.number.int()
  • Loading branch information
jamalsoueidan committed Oct 12, 2023
1 parent c29bbbf commit a8ad56a
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/functions/customer/controllers/customer/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("CustomerControllerUpdate", () => {
let context: InvocationContext;
let request: HttpRequest;

const query = { customerId: faker.datatype.number() };
const query = { customerId: faker.number.int() };
const body: CustomerControllerUpdateBody = {
yearsExperience: 1,
fullname: "test",
Expand Down
2 changes: 1 addition & 1 deletion src/functions/customer/controllers/customer/upsert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("CustomerControllerUpsert", () => {
let context: InvocationContext;
let request: HttpRequest;

const query = { customerId: faker.datatype.number() };
const query = { customerId: faker.number.int() };
const body: CustomerControllerUpsertBody = {
yearsExperience: 1,
username: faker.internet.userName(),
Expand Down
12 changes: 6 additions & 6 deletions src/functions/customer/services/availability.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ jest.mock("~/functions/lookup", () => {
LookupServiceCreate: jest.fn().mockResolvedValueOnce({
_id: new mongoose.Types.ObjectId(),
origin: {
name: faker.name.firstName(),
customerId: faker.datatype.number({ min: 1, max: 100000 }),
name: faker.person.firstName(),
customerId: faker.number.int({ min: 1, max: 100000 }),
fullAddress: faker.address.streetAddress(),
distanceHourlyRate: faker.datatype.number({ min: 1, max: 5 }),
fixedRatePerKm: faker.datatype.number({ min: 1, max: 5 }),
minDistanceForFree: faker.datatype.number({ min: 1, max: 5 }),
distanceHourlyRate: faker.number.int({ min: 1, max: 5 }),
fixedRatePerKm: faker.number.int({ min: 1, max: 5 }),
minDistanceForFree: faker.number.int({ min: 1, max: 5 }),
},
destination: {
name: faker.name.firstName(),
name: faker.person.firstName(),
fullAddress: faker.address.streetAddress(),
},
duration: {
Expand Down
12 changes: 6 additions & 6 deletions src/functions/customer/services/customer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require("~/library/jest/mongoose/mongodb.jest");
describe("CustomerService", () => {
const userData: CustomerServiceUpsertBody = {
username: faker.internet.userName(),
fullname: faker.name.fullName(),
fullname: faker.person.fullName(),
social: {
instagram: faker.internet.url(),
youtube: faker.internet.url(),
Expand All @@ -31,7 +31,7 @@ describe("CustomerService", () => {

it("Should create a user", async () => {
const newUser = await CustomerServiceUpsert(
{ customerId: faker.datatype.number() },
{ customerId: faker.number.int() },
userData
);

Expand All @@ -40,7 +40,7 @@ describe("CustomerService", () => {

it("Should get the customer by customerId", async () => {
const newUser = await CustomerServiceUpsert(
{ customerId: faker.datatype.number() },
{ customerId: faker.number.int() },
userData
);

Expand All @@ -53,7 +53,7 @@ describe("CustomerService", () => {

it("Should check if customer exist", async () => {
const newUser = await CustomerServiceUpsert(
{ customerId: faker.datatype.number() },
{ customerId: faker.number.int() },
userData
);

Expand All @@ -64,14 +64,14 @@ describe("CustomerService", () => {
});

it("Should update a user by customerId", async () => {
const filter = { customerId: faker.datatype.number() };
const filter = { customerId: faker.number.int() };
// Create a user first
await CustomerServiceUpsert(filter, userData);

// Update the user
const updatedData: CustomerServiceUpsertBody = {
...userData,
fullname: faker.name.fullName(),
fullname: faker.person.fullName(),
};

const updatedUser = await CustomerServiceUpsert(filter, updatedData);
Expand Down
2 changes: 1 addition & 1 deletion src/functions/customer/services/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
require("~/library/jest/mongoose/mongodb.jest");

describe("CustomerLocationService", () => {
const customerId = faker.datatype.number();
const customerId = faker.number.int();

const location1: Location = {
name: "Falafel 1",
Expand Down
10 changes: 5 additions & 5 deletions src/functions/lookup/lookup.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jest.mock("~/functions/location/services", () => {
LocationServiceLookup: jest.fn().mockResolvedValueOnce({
location: {
_id: new mongoose.Types.ObjectId(),
name: faker.name.firstName(),
customerId: faker.datatype.number({ min: 1, max: 100000 }),
name: faker.person.firstName(),
customerId: faker.number.int({ min: 1, max: 100000 }),
fullAddress: faker.address.streetAddress(),
distanceHourlyRate: faker.datatype.number({ min: 1, max: 5 }),
fixedRatePerKm: faker.datatype.number({ min: 1, max: 5 }),
minDistanceForFree: faker.datatype.number({ min: 1, max: 5 }),
distanceHourlyRate: faker.number.int({ min: 1, max: 5 }),
fixedRatePerKm: faker.number.int({ min: 1, max: 5 }),
minDistanceForFree: faker.number.int({ min: 1, max: 5 }),
},
travelTime: {
duration: { text: "14 mins", value: 831 },
Expand Down
12 changes: 6 additions & 6 deletions src/functions/shipping/shipping.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe("ShippingService", () => {
it("should correctly calculate the cost", () => {
const lookup = {
origin: {
name: faker.name.firstName(),
customerId: faker.datatype.number({ min: 1, max: 100000 }),
name: faker.person.firstName(),
customerId: faker.number.int({ min: 1, max: 100000 }),
fullAddress: faker.address.streetAddress(),
distanceHourlyRate: 100,
fixedRatePerKm: 20,
minDistanceForFree: 5,
},
destination: {
name: faker.name.firstName(),
name: faker.person.firstName(),
fullAddress: faker.address.streetAddress(),
},
duration: {
Expand All @@ -44,15 +44,15 @@ describe("ShippingService", () => {
it("should calculate destination in available slots", async () => {
const lookup = await LookupModel.create({
origin: {
name: faker.name.firstName(),
customerId: faker.datatype.number({ min: 1, max: 100000 }),
name: faker.person.firstName(),
customerId: faker.number.int({ min: 1, max: 100000 }),
fullAddress: faker.address.streetAddress(),
distanceHourlyRate: 100,
fixedRatePerKm: 20,
minDistanceForFree: 5,
},
destination: {
name: faker.name.firstName(),
name: faker.person.firstName(),
fullAddress: faker.address.streetAddress(),
},
duration: {
Expand Down
10 changes: 5 additions & 5 deletions src/functions/user/services/schedule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("UserScheduleService", () => {
});

const schedule1 = await CustomerScheduleServiceCreate({
name: faker.name.firstName(),
name: faker.person.firstName(),
customerId,
products: [
getProductObject({
Expand All @@ -52,7 +52,7 @@ describe("UserScheduleService", () => {
});

const schedule2 = await CustomerScheduleServiceCreate({
name: faker.name.firstName(),
name: faker.person.firstName(),
customerId,
products: [
getProductObject({
Expand All @@ -75,7 +75,7 @@ describe("UserScheduleService", () => {
});

await CustomerScheduleServiceCreate({
name: faker.name.firstName(),
name: faker.person.firstName(),
customerId,
products: [],
});
Expand All @@ -102,7 +102,7 @@ describe("UserScheduleService", () => {

it("should return none schedules when schedule does not contain any products", async () => {
await CustomerScheduleServiceCreate({
name: faker.name.firstName(),
name: faker.person.firstName(),
customerId,
products: [],
});
Expand All @@ -122,7 +122,7 @@ describe("UserScheduleService", () => {
});

const schedule = await CustomerScheduleServiceCreate({
name: faker.name.firstName(),
name: faker.person.firstName(),
customerId,
products: [
getProductObject({
Expand Down
6 changes: 3 additions & 3 deletions src/functions/user/services/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ require("~/library/jest/mongoose/mongodb.jest");
describe("UserService", () => {
it("Should find user", async () => {
// Create multiple users
const filter = { customerId: faker.datatype.number() };
const filter = { customerId: faker.number.int() };
const username = faker.internet.userName();
// Create a user first
const userData: CustomerServiceUpsertBody = {
yearsExperience: 1,
professions: [Professions.MAKEUP_ARTIST],
username,
fullname: faker.name.fullName(),
fullname: faker.person.fullName(),
shortDescription: faker.lorem.paragraph(),
aboutMe: faker.lorem.paragraph(),
speaks: [faker.location.countryCode()],
Expand Down Expand Up @@ -79,7 +79,7 @@ describe("UserService", () => {
it("Should get group and count professions by all users", async () => {
const professions = Object.values(Professions);

const professionCount = faker.datatype.number({
const professionCount = faker.number.int({
min: 1,
max: professions.length,
});
Expand Down
10 changes: 5 additions & 5 deletions src/library/jest/helpers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { User } from "~/functions/user";
export const DEFAULT_GROUP = "all";

export const getLocationObject = (props: Partial<Location> = {}): Location => ({
name: faker.name.firstName(),
customerId: faker.datatype.number({ min: 1, max: 100000 }),
name: faker.person.firstName(),
customerId: faker.number.int({ min: 1, max: 100000 }),
locationType: LocationTypes.ORIGIN,
originType: LocationOriginTypes.COMMERCIAL,
fullAddress: faker.address.streetAddress(),
distanceHourlyRate: faker.datatype.number({ min: 1, max: 5 }),
fixedRatePerKm: faker.datatype.number({ min: 1, max: 5 }),
minDistanceForFree: faker.datatype.number({ min: 1, max: 5 }),
distanceHourlyRate: faker.number.int({ min: 1, max: 5 }),
fixedRatePerKm: faker.number.int({ min: 1, max: 5 }),
minDistanceForFree: faker.number.int({ min: 1, max: 5 }),
...props,
});

Expand Down
4 changes: 2 additions & 2 deletions src/library/jest/helpers/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ScheduleProduct, TimeUnit } from "~/functions/schedule";
export const getProductObject = (
props: Partial<ScheduleProduct> = {}
): ScheduleProduct => ({
productId: faker.datatype.number({ min: 1, max: 10000000 }),
variantId: faker.datatype.number({ min: 1, max: 10000000 }),
productId: faker.number.int({ min: 1, max: 10000000 }),
variantId: faker.number.int({ min: 1, max: 10000000 }),
duration: faker.helpers.arrayElement([30, 45, 60]),
breakTime: faker.helpers.arrayElement([5, 10, 15]),
bookingPeriod: {
Expand Down
2 changes: 1 addition & 1 deletion src/library/jest/helpers/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getScheduleObject = (

return {
name: faker.random.word(),
customerId: faker.datatype.number(),
customerId: faker.number.int(),
slots,
products,
...props,
Expand Down
4 changes: 2 additions & 2 deletions src/library/jest/helpers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { User } from "~/functions/user";
export const DEFAULT_GROUP = "all";

export const getUserObject = (props: Partial<User> = {}) => ({
title: faker.name.jobTitle(),
title: faker.person.jobTitle(),
username: faker.internet.userName().toLowerCase(),
fullname: faker.name.fullName(),
fullname: faker.person.fullName(),
social: {
instagram: faker.internet.url(),
youtube: faker.internet.url(),
Expand Down

0 comments on commit a8ad56a

Please sign in to comment.