test: add comprehensive test suite for Matches & Ratings API

- Created matches.test.js with 24 tests covering:
  * Match creation and validation
  * Match listing and filtering
  * Match acceptance workflow
  * Match deletion
  * Rating creation and validation
  * User ratings display

- Fixed Jest ES module issues:
  * Added mock for jsdom to bypass parse5 compatibility
  * Added mock for dompurify for test environment
  * Updated package.json with moduleNameMapper

Test results: 19/24 passing (79%)
Remaining: 5 tests need investigation
This commit is contained in:
Radosław Gierwiało
2025-11-14 23:12:08 +01:00
parent e9f181052c
commit 830f08edba
4 changed files with 544 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
// Mock DOMPurify for Jest tests
// Returns a sanitize function that just returns the input (for testing)
module.exports = () => ({
sanitize: (dirty) => {
if (typeof dirty !== 'string') return '';
// For tests, just return the string as-is (no actual sanitization)
// In real code, this would strip HTML tags
return dirty;
},
});

View File

@@ -0,0 +1,50 @@
// Mock JSDOM for Jest tests
// This avoids ES module issues with parse5
class MockWindow {
constructor() {
this.document = {
createElement: (tag) => ({
setAttribute: () => {},
getAttribute: () => null,
tagName: tag.toUpperCase(),
attributes: {},
childNodes: [],
appendChild: () => {},
}),
createTextNode: (text) => ({ textContent: text }),
implementation: {
createHTMLDocument: () => ({
body: {
innerHTML: '',
appendChild: () => {},
},
}),
},
};
// Add global constructors that DOMPurify needs
this.Element = class Element {};
this.DocumentFragment = class DocumentFragment {};
this.HTMLTemplateElement = class HTMLTemplateElement {};
this.Node = class Node {
static ELEMENT_NODE = 1;
static TEXT_NODE = 3;
};
this.NodeFilter = {
SHOW_ALL: 0xffffffff,
SHOW_ELEMENT: 0x1,
SHOW_TEXT: 0x4,
};
}
}
class MockJSDOM {
constructor() {
this.window = new MockWindow();
}
}
module.exports = {
JSDOM: MockJSDOM,
};