Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General fixes to dependencies, tests and code to be able to run tests #479

Open
wants to merge 1 commit into
base: v1.x
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ node/**/!(main).js
node/**/*.js.map
.vscode/
.DS_Store
node/package-lock.json
node/package-lock.json
.yarn/
.pnp.cjs
.pnp.loader.mjs
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Fixed tests in helpers.ts
- By adding mocks for clients for:
- vbase
- intelligentSearchAPI
- Fixed in newURL test
- To return something instead of void in saveJSON function
- Fixed to have facets with all previous object properties
- Fixed to have requirement properties (Quantity, Link, LinkEncoded)
- Fixed in product test
- Fixed adding tests to test not undefined and and length verification qadd conditional test for result
- Fixed having speficiationGroups different than undefined
- Fixed adding tests to test not undefined and length greater than 0 and add conditional test for specificationGroups
- Fixed generic types in product.ts
- Fixed from utils.ts
- import for crypto
- adding children property from category getCategoryInfo function
- Typescript required as dev dependency instead in node
- And version 4 to make sure right generic types work in product.ts

### Removed

- Removed wrong tests from productSearch.test.ts because they were asserting from mock rather than actual functionality.

### Added

- Dev dependencies at root level to be able to run:
- Tests
- Lint

## [1.71.0] - 2024-07-09

### Added
Expand Down
45 changes: 45 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import jest from "eslint-plugin-jest"

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("vtex"), {
languageOptions: {
globals: {
...globals.jest,
...globals.node,
metrics: true,
},
parserOptions: {
project: true
}
},

plugins: {
jest
},

files: [
"**/*.ts", "**/*.tsx",
"**/*.js", "**/*.jsx",
],

rules: {
"prettier/prettier": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
},
}];
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest",{}],
},
};
45 changes: 38 additions & 7 deletions node/__mocks__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const searchClientMock = {
categories: jest.fn(),
crossSelling: jest.fn(),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
productById: jest.fn((_id: string, _cacheable: boolean = true) => promisify(null)),
productById: jest.fn((_id: string, _cacheable: boolean = true) =>
promisify(null)
),
filtersInCategoryFromId: jest.fn(),
}

Expand All @@ -35,10 +37,28 @@ const segmentClientMock = {
}),
}

/**
* Added getJSON function so it doesn't fail during tests with unknown or undefined
*/
const vbaseMock = {
getJSON: () => {},
}

/**
* Added getJSON function so it doesn't fail during tests with unknown or undefined
*/
const intelligentSearchApiMock = {
productSearch: () => {
return { translated: { jk: 'jk' } }
},
}

export const getBindingLocale = () => mockContext.vtex.binding.locale

const rewriterClientMock: any = {
getRoute: jest.fn((id: string, type: string, bindingId: string) => promisify(`${id}-${type}-${bindingId}-${getBindingLocale()}`))
getRoute: jest.fn((id: string, type: string, bindingId: string) =>
promisify(`${id}-${type}-${bindingId}-${getBindingLocale()}`)
),
}

const getLocale = () => mockContext.vtex.locale
Expand All @@ -49,12 +69,15 @@ const initialCtxState = {
platform: 'vtex',
locale: 'pt-BR',
tenant: { locale: 'pt-BR' },
binding: { id: 'abc', locale: 'pt-BR' }
binding: { id: 'abc', locale: 'pt-BR' },
}

const generateDeepCopy = (obj: any) => JSON.parse(JSON.stringify(obj))

export const mockContext: any = {
/**
* added mocked clients vbase and intelligentSearchAPI defined above
*/
vtex: {
...generateDeepCopy(initialCtxState),
},
Expand All @@ -63,15 +86,23 @@ export const mockContext: any = {
segment: segmentClientMock,
messagesGraphQL: messagesGraphQLClientMock,
rewriter: rewriterClientMock,
vbase: vbaseMock,
intelligentSearchApi: intelligentSearchApiMock,
},
state: {
messagesBindingLanguage: {
loadMany: jest.fn((messages: any) => messages.map((message: any) => `${message.content}-${getLocale()}`))
loadMany: jest.fn((messages: any) =>
messages.map((message: any) => `${message.content}-${getLocale()}`)
),
},
messagesTenantLanguage: {
load: jest.fn((message: any) => `${message.content}-${getTenantLocale()}`)
}
load: jest.fn(
(message: any) => `${message.content}-${getTenantLocale()}`
),
},
},
}

export const resetContext = () => {mockContext.vtex = { ...generateDeepCopy(initialCtxState) }}
export const resetContext = () => {
mockContext.vtex = { ...generateDeepCopy(initialCtxState) }
}
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"querystring": "^0.2.0",
"ramda": "^0.27.1",
"slugify": "^1.6.4",
"typescript": "3.9.7",
"unescape": "^1.0.1",
"vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.54.0-beta.1/public"
},
"devDependencies": {
"typescript": "^4",
"@types/atob": "^2.1.2",
"@types/camelcase": "^4.1.0",
"@types/cookie": "^0.4.1",
Expand Down
Loading