This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run via: node isOdd.test.js | |
import test from 'node:test' | |
import assert from 'assert' | |
const isOdd = (val) => val % 2 | |
test('isOdd', () => { | |
[[1, true], [2, false]].forEach(([input, expected]) => { | |
test(`Is Odd for value ${input}`, () => { | |
assert.equal(isOdd(input), expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { object, string } from "yup" | |
export const userSchema = object({ | |
id: string().uuid(), | |
username: string().required(), | |
email: string().email().required(), | |
country: string().required(), | |
department: string().required(), | |
divisionName: string().required(), | |
city: string().optional(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { User, userSchema } from "../../src/userService" | |
import { fake } from "yup-schema-faker" | |
export const createUser = (data: Partial<User> = {}): User => { | |
const fakeSchemaData = fake(userSchema.noUnknown()) as User; | |
return { | |
...fakeSchemaData, | |
...data, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as faker from "faker" | |
import { User } from "../../src/userService" | |
export const createUser = (data: Partial<User> = {}) : User => { | |
const fakeData: User = { | |
id: faker.datatype.uuid(), | |
username: faker.name.findName(), | |
email: faker.internet.email(), | |
country: faker.address.country(), | |
department: faker.company.companyName(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as faker from "faker" | |
import { User } from "../../src/userService" | |
export const createUser = (data: Partial<User> = {}) => { | |
const fakeData: User = { | |
username: faker.name.findName(), | |
email: faker.internet.email(), | |
country: faker.address.country(), | |
department: faker.company.companyName(), | |
divisionName: faker.name.jobArea(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { updateUser } from "./userService" | |
import { createUser } from "../tests/helpers/createUser" | |
describe('UserService - updateUser', () => { | |
it('should update department', () => { | |
// GIVEN | |
const user = createUser() | |
const updateData = { | |
department: 'IT Support', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const createUser = () => ({ | |
id: 'e2f5a82a-3f2e-4b6d-b4d2-086afaa08f8a', | |
username: 'john', | |
email: '[email protected]', | |
country: 'France', | |
department: 'IT Services', | |
divisionName: 'IT', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { updateUser } from "./userService" | |
describe('UserService - updateUser', () => { | |
it('should update department', () => { | |
// GIVEN | |
const user = { | |
id: 'e2f5a82a-3f2e-4b6d-b4d2-086afaa08f8a', | |
username: 'john', | |
email: '[email protected]', | |
country: 'France', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const seedValue = 100; | |
faker.seed(seedValue); | |
console.log(faker.name.findName()); | |
// Vždy vypíše stejné jméno: "Eva Jenkins" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import faker from 'faker'; | |
const setupFaker = () => { | |
const replayedSeed = parseInt(process.env.FAKER_SEED, 10) || 0; | |
const seedValue = replayedSeed || Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); | |
faker.seed(seedValue); | |
if (replayedSeed) { | |
console.warn(`Replaying test with FAKER_SEED=${replayedSeed}`); | |
} else { | |
console.info(`FAKER_SEED=${seedValue}`); |
NewerOlder