feature/mongodb-to-couchdb-migration #1
@@ -1,24 +1,22 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
}));
|
initialize: jest.fn(),
|
||||||
|
getDocument: jest.fn(),
|
||||||
|
findUserById: jest.fn(),
|
||||||
|
update: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const Comment = require('../../models/Comment');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const Post = require('../../models/Post');
|
|
||||||
const couchdbService = require('../../services/couchdbService');
|
|
||||||
|
|
||||||
describe('Comment Model', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
// Reset all mocks to ensure clean state
|
// Reset all mocks to ensure clean state
|
||||||
couchdbService.createDocument.mockReset();
|
mockCouchdbService.createDocument.mockReset();
|
||||||
couchdbService.findDocumentById.mockReset();
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
couchdbService.updateDocument.mockReset();
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
couchdbService.findByType.mockReset();
|
mockCouchdbService.findByType.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -39,7 +37,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -97,7 +95,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -123,7 +121,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -159,7 +157,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -184,7 +182,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -209,7 +207,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -236,8 +234,8 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockComment);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockComment);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockComment,
|
...mockComment,
|
||||||
likes: ['user_456'],
|
likes: ['user_456'],
|
||||||
_rev: '2-def'
|
_rev: '2-def'
|
||||||
@@ -270,7 +268,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -294,7 +292,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -320,7 +318,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -347,8 +345,8 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockComment);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockComment);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockComment,
|
...mockComment,
|
||||||
content: 'Updated comment content',
|
content: 'Updated comment content',
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -383,7 +381,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -407,7 +405,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const comment = await Comment.create(commentData);
|
const comment = await Comment.create(commentData);
|
||||||
|
|
||||||
@@ -429,7 +427,7 @@ describe('Comment Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockComment);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockComment);
|
||||||
|
|
||||||
const comment = await Comment.findById('comment_123');
|
const comment = await Comment.findById('comment_123');
|
||||||
expect(comment).toBeDefined();
|
expect(comment).toBeDefined();
|
||||||
@@ -438,10 +436,10 @@ describe('Comment Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when comment not found', async () => {
|
it('should return null when comment not found', async () => {
|
||||||
couchdbService.findDocumentById.mockResolvedValue(null);
|
mockCouchdbService.findDocumentById.mockResolvedValue(null);
|
||||||
|
|
||||||
const comment = await Comment.findById('nonexistent');
|
const comment = await Comment.findById('nonexistent');
|
||||||
expect(comment).toBeNull();
|
expect(comment).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,29 +1,27 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
create: jest.fn(),
|
initialize: jest.fn(),
|
||||||
getById: jest.fn(),
|
getDocument: jest.fn(),
|
||||||
find: jest.fn(),
|
findUserById: jest.fn(),
|
||||||
}));
|
update: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const Event = require('../../models/Event');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const couchdbService = require('../../services/couchdbService');
|
|
||||||
|
|
||||||
describe('Event Model', () => {
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
// Reset all mocks to ensure clean state
|
// Reset all mocks to ensure clean state
|
||||||
couchdbService.createDocument.mockReset();
|
mockCouchdbService.createDocument.mockReset();
|
||||||
couchdbService.findDocumentById.mockReset();
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
couchdbService.updateDocument.mockReset();
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
couchdbService.findByType.mockReset();
|
mockCouchdbService.findByType.mockReset();
|
||||||
couchdbService.create.mockReset();
|
mockCouchdbService.create.mockReset();
|
||||||
couchdbService.getById.mockReset();
|
mockCouchdbService.getById.mockReset();
|
||||||
couchdbService.find.mockReset();
|
mockCouchdbService.find.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -47,7 +45,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.create.mockResolvedValue(mockCreated);
|
mockCouchdbService.create.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -122,7 +120,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -151,7 +149,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -180,7 +178,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -214,7 +212,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -255,7 +253,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -288,7 +286,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -319,7 +317,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -348,8 +346,8 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockEvent);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockEvent);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockEvent,
|
...mockEvent,
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -391,7 +389,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const event = await Event.create(eventData);
|
const event = await Event.create(eventData);
|
||||||
|
|
||||||
@@ -416,7 +414,7 @@ describe('Event Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockEvent);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockEvent);
|
||||||
|
|
||||||
const event = await Event.findById('event_123');
|
const event = await Event.findById('event_123');
|
||||||
expect(event).toBeDefined();
|
expect(event).toBeDefined();
|
||||||
@@ -425,10 +423,10 @@ describe('Event Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when event not found', async () => {
|
it('should return null when event not found', async () => {
|
||||||
couchdbService.findDocumentById.mockResolvedValue(null);
|
mockCouchdbService.findDocumentById.mockResolvedValue(null);
|
||||||
|
|
||||||
const event = await Event.findById('nonexistent');
|
const event = await Event.findById('nonexistent');
|
||||||
expect(event).toBeNull();
|
expect(event).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
}));
|
initialize: jest.fn(),
|
||||||
|
getDocument: jest.fn(),
|
||||||
|
findUserById: jest.fn(),
|
||||||
|
update: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const PointTransaction = require('../../models/PointTransaction');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const couchdbService = require('../../services/couchdbService');
|
mockCouchdbService.createDocument.mockReset();
|
||||||
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
describe('PointTransaction Model', () => {
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
beforeEach(() => {
|
mockCouchdbService.findByType.mockReset();
|
||||||
jest.clearAllMocks();
|
|
||||||
// Reset all mocks to ensure clean state
|
|
||||||
couchdbService.createDocument.mockReset();
|
|
||||||
couchdbService.findDocumentById.mockReset();
|
|
||||||
couchdbService.updateDocument.mockReset();
|
|
||||||
couchdbService.findByType.mockReset();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -42,7 +40,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -117,7 +115,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -155,7 +153,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -179,7 +177,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -203,7 +201,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -227,7 +225,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -258,7 +256,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -284,7 +282,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -325,7 +323,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -352,7 +350,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -378,7 +376,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const transaction = await PointTransaction.create(transactionData);
|
const transaction = await PointTransaction.create(transactionData);
|
||||||
|
|
||||||
@@ -405,8 +403,8 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockTransaction);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockTransaction);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockTransaction,
|
...mockTransaction,
|
||||||
description: 'Updated transaction description',
|
description: 'Updated transaction description',
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -437,7 +435,7 @@ describe('PointTransaction Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockTransaction);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockTransaction);
|
||||||
|
|
||||||
const transaction = await PointTransaction.findById('point_transaction_123');
|
const transaction = await PointTransaction.findById('point_transaction_123');
|
||||||
expect(transaction).toBeDefined();
|
expect(transaction).toBeDefined();
|
||||||
@@ -446,7 +444,7 @@ describe('PointTransaction Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when transaction not found', async () => {
|
it('should return null when transaction not found', async () => {
|
||||||
couchdbService.findDocumentById.mockResolvedValue(null);
|
mockCouchdbService.findDocumentById.mockResolvedValue(null);
|
||||||
|
|
||||||
const transaction = await PointTransaction.findById('nonexistent');
|
const transaction = await PointTransaction.findById('nonexistent');
|
||||||
expect(transaction).toBeNull();
|
expect(transaction).toBeNull();
|
||||||
@@ -478,7 +476,7 @@ describe('PointTransaction Model', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
couchdbService.findByType.mockResolvedValue(mockTransactions);
|
mockCouchdbService.findByType.mockResolvedValue(mockTransactions);
|
||||||
|
|
||||||
const transactions = await PointTransaction.findByUser('user_123');
|
const transactions = await PointTransaction.findByUser('user_123');
|
||||||
expect(transactions).toHaveLength(2);
|
expect(transactions).toHaveLength(2);
|
||||||
@@ -513,17 +511,17 @@ describe('PointTransaction Model', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
couchdbService.findByType.mockResolvedValue(mockTransactions);
|
mockCouchdbService.findByType.mockResolvedValue(mockTransactions);
|
||||||
|
|
||||||
const balance = await PointTransaction.getUserBalance('user_123');
|
const balance = await PointTransaction.getUserBalance('user_123');
|
||||||
expect(balance).toBe(125); // 100 - 25 + 50
|
expect(balance).toBe(125); // 100 - 25 + 50
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 0 for user with no transactions', async () => {
|
it('should return 0 for user with no transactions', async () => {
|
||||||
couchdbService.findByType.mockResolvedValue([]);
|
mockCouchdbService.findByType.mockResolvedValue([]);
|
||||||
|
|
||||||
const balance = await PointTransaction.getUserBalance('user_456');
|
const balance = await PointTransaction.getUserBalance('user_456');
|
||||||
expect(balance).toBe(0);
|
expect(balance).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
|
initialize: jest.fn(),
|
||||||
|
getDocument: jest.fn(),
|
||||||
findUserById: jest.fn(),
|
findUserById: jest.fn(),
|
||||||
create: jest.fn(),
|
|
||||||
getById: jest.fn(),
|
|
||||||
update: jest.fn(),
|
update: jest.fn(),
|
||||||
}));
|
};
|
||||||
|
|
||||||
const Post = require('../../models/Post');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const couchdbService = require('../../services/couchdbService');
|
|
||||||
|
|
||||||
describe('Post Model', () => {
|
describe('Post Model', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
// Reset all mocks to ensure clean state
|
// Reset all mocks to ensure clean state
|
||||||
couchdbService.createDocument.mockReset();
|
mockCouchdbService.createDocument.mockReset();
|
||||||
couchdbService.findDocumentById.mockReset();
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
couchdbService.updateDocument.mockReset();
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
couchdbService.findByType.mockReset();
|
mockCouchdbService.findByType.mockReset();
|
||||||
couchdbService.findUserById.mockReset();
|
mockCouchdbService.findUserById.mockReset();
|
||||||
couchdbService.create.mockReset();
|
mockCouchdbService.create.mockReset();
|
||||||
couchdbService.getById.mockReset();
|
mockCouchdbService.getById.mockReset();
|
||||||
couchdbService.update.mockReset();
|
mockCouchdbService.update.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -61,9 +60,9 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findUserById.mockResolvedValue(mockUser);
|
mockCouchdbService.findUserById.mockResolvedValue(mockUser);
|
||||||
couchdbService.create.mockResolvedValue(mockCreated);
|
mockCouchdbService.create.mockResolvedValue(mockCreated);
|
||||||
couchdbService.update.mockResolvedValue({});
|
mockCouchdbService.update.mockResolvedValue({});
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -98,7 +97,7 @@ describe('Post Model', () => {
|
|||||||
stats: { postsCreated: 0 }
|
stats: { postsCreated: 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findUserById.mockResolvedValue(mockUser);
|
mockCouchdbService.findUserById.mockResolvedValue(mockUser);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
expect(post.content).toBeUndefined();
|
expect(post.content).toBeUndefined();
|
||||||
@@ -130,9 +129,9 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findUserById.mockResolvedValue(mockUser);
|
mockCouchdbService.findUserById.mockResolvedValue(mockUser);
|
||||||
couchdbService.create.mockResolvedValue(mockCreated);
|
mockCouchdbService.create.mockResolvedValue(mockCreated);
|
||||||
couchdbService.update.mockResolvedValue({});
|
mockCouchdbService.update.mockResolvedValue({});
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
expect(post.type).toBe('post'); // Default type
|
expect(post.type).toBe('post'); // Default type
|
||||||
@@ -171,9 +170,9 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findUserById.mockResolvedValue(mockUser);
|
mockCouchdbService.findUserById.mockResolvedValue(mockUser);
|
||||||
couchdbService.create.mockResolvedValue(mockCreated);
|
mockCouchdbService.create.mockResolvedValue(mockCreated);
|
||||||
couchdbService.update.mockResolvedValue({});
|
mockCouchdbService.update.mockResolvedValue({});
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -213,7 +212,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -239,7 +238,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -267,7 +266,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -293,7 +292,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -318,7 +317,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -346,7 +345,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -372,7 +371,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -398,7 +397,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -425,7 +424,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -453,8 +452,8 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockPost);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockPost);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockPost,
|
...mockPost,
|
||||||
content: 'Updated content',
|
content: 'Updated content',
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -488,7 +487,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -513,7 +512,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -541,7 +540,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -568,7 +567,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
@@ -596,7 +595,7 @@ describe('Post Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const post = await Post.create(postData);
|
const post = await Post.create(postData);
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
}));
|
initialize: jest.fn(),
|
||||||
|
getDocument: jest.fn(),
|
||||||
|
findUserById: jest.fn(),
|
||||||
|
update: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const Report = require('../../models/Report');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const Street = require('../../models/Street');
|
|
||||||
const couchdbService = require('../../services/couchdbService');
|
|
||||||
|
|
||||||
describe('Report Model', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
// Reset all mocks to ensure clean state
|
// Reset all mocks to ensure clean state
|
||||||
couchdbService.createDocument.mockReset();
|
mockCouchdbService.createDocument.mockReset();
|
||||||
couchdbService.findDocumentById.mockReset();
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
couchdbService.updateDocument.mockReset();
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
couchdbService.findByType.mockReset();
|
mockCouchdbService.findByType.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -46,7 +44,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -123,7 +121,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -164,7 +162,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -194,7 +192,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -228,7 +226,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -256,7 +254,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -285,7 +283,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -313,7 +311,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -343,8 +341,8 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReport);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReport);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockReport,
|
...mockReport,
|
||||||
status: 'resolved',
|
status: 'resolved',
|
||||||
_rev: '2-def'
|
_rev: '2-def'
|
||||||
@@ -379,7 +377,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -409,8 +407,8 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReport);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReport);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockReport,
|
...mockReport,
|
||||||
status: 'in_progress',
|
status: 'in_progress',
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -450,7 +448,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const report = await Report.create(reportData);
|
const report = await Report.create(reportData);
|
||||||
|
|
||||||
@@ -475,7 +473,7 @@ describe('Report Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReport);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReport);
|
||||||
|
|
||||||
const report = await Report.findById('report_123');
|
const report = await Report.findById('report_123');
|
||||||
expect(report).toBeDefined();
|
expect(report).toBeDefined();
|
||||||
@@ -484,10 +482,10 @@ describe('Report Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when report not found', async () => {
|
it('should return null when report not found', async () => {
|
||||||
couchdbService.findDocumentById.mockResolvedValue(null);
|
mockCouchdbService.findDocumentById.mockResolvedValue(null);
|
||||||
|
|
||||||
const report = await Report.findById('nonexistent');
|
const report = await Report.findById('nonexistent');
|
||||||
expect(report).toBeNull();
|
expect(report).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
}));
|
initialize: jest.fn(),
|
||||||
|
getDocument: jest.fn(),
|
||||||
|
findUserById: jest.fn(),
|
||||||
|
update: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const Reward = require('../../models/Reward');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const couchdbService = require('../../services/couchdbService');
|
mockCouchdbService.createDocument.mockReset();
|
||||||
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
describe('Reward Model', () => {
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
beforeEach(() => {
|
mockCouchdbService.findByType.mockReset();
|
||||||
jest.clearAllMocks();
|
|
||||||
// Reset all mocks to ensure clean state
|
|
||||||
couchdbService.createDocument.mockReset();
|
|
||||||
couchdbService.findDocumentById.mockReset();
|
|
||||||
couchdbService.updateDocument.mockReset();
|
|
||||||
couchdbService.findByType.mockReset();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -40,7 +38,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -109,7 +107,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -134,7 +132,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -166,7 +164,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -197,7 +195,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -235,7 +233,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -260,8 +258,8 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReward);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReward);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockReward,
|
...mockReward,
|
||||||
isActive: false,
|
isActive: false,
|
||||||
_rev: '2-def'
|
_rev: '2-def'
|
||||||
@@ -305,7 +303,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -332,8 +330,8 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReward);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReward);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockReward,
|
...mockReward,
|
||||||
redeemedBy: [
|
redeemedBy: [
|
||||||
{
|
{
|
||||||
@@ -377,7 +375,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const reward = await Reward.create(rewardData);
|
const reward = await Reward.create(rewardData);
|
||||||
|
|
||||||
@@ -405,8 +403,8 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReward);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReward);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockReward,
|
...mockReward,
|
||||||
isActive: false,
|
isActive: false,
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -438,7 +436,7 @@ describe('Reward Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockReward);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockReward);
|
||||||
|
|
||||||
const reward = await Reward.findById('reward_123');
|
const reward = await Reward.findById('reward_123');
|
||||||
expect(reward).toBeDefined();
|
expect(reward).toBeDefined();
|
||||||
@@ -447,10 +445,10 @@ describe('Reward Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when reward not found', async () => {
|
it('should return null when reward not found', async () => {
|
||||||
couchdbService.findDocumentById.mockResolvedValue(null);
|
mockCouchdbService.findDocumentById.mockResolvedValue(null);
|
||||||
|
|
||||||
const reward = await Reward.findById('nonexistent');
|
const reward = await Reward.findById('nonexistent');
|
||||||
expect(reward).toBeNull();
|
expect(reward).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
// Mock CouchDB service for testing
|
// Mock CouchDB service for testing
|
||||||
jest.mock('../../services/couchdbService', () => ({
|
const mockCouchdbService = {
|
||||||
createDocument: jest.fn(),
|
createDocument: jest.fn(),
|
||||||
findDocumentById: jest.fn(),
|
findDocumentById: jest.fn(),
|
||||||
updateDocument: jest.fn(),
|
updateDocument: jest.fn(),
|
||||||
findByType: jest.fn(),
|
findByType: jest.fn(),
|
||||||
}));
|
initialize: jest.fn(),
|
||||||
|
getDocument: jest.fn(),
|
||||||
|
findUserById: jest.fn(),
|
||||||
|
update: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const UserBadge = require('../../models/UserBadge');
|
// Mock the service module
|
||||||
const User = require('../../models/User');
|
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||||
const Badge = require('../../models/Badge');
|
|
||||||
const couchdbService = require('../../services/couchdbService');
|
|
||||||
|
|
||||||
describe('UserBadge Model', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
// Reset all mocks to ensure clean state
|
// Reset all mocks to ensure clean state
|
||||||
couchdbService.createDocument.mockReset();
|
mockCouchdbService.createDocument.mockReset();
|
||||||
couchdbService.findDocumentById.mockReset();
|
mockCouchdbService.findDocumentById.mockReset();
|
||||||
couchdbService.updateDocument.mockReset();
|
mockCouchdbService.updateDocument.mockReset();
|
||||||
couchdbService.findByType.mockReset();
|
mockCouchdbService.findByType.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Schema Validation', () => {
|
describe('Schema Validation', () => {
|
||||||
@@ -38,7 +36,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -93,7 +91,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -120,7 +118,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findByType.mockResolvedValue([existingUserBadge]);
|
mockCouchdbService.findByType.mockResolvedValue([existingUserBadge]);
|
||||||
|
|
||||||
// This should be handled at the service level, but we test the model validation
|
// This should be handled at the service level, but we test the model validation
|
||||||
const mockCreated = {
|
const mockCreated = {
|
||||||
@@ -132,7 +130,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -165,7 +163,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -191,7 +189,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -214,7 +212,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -239,7 +237,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
mockCouchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||||
|
|
||||||
const userBadge = await UserBadge.create(userBadgeData);
|
const userBadge = await UserBadge.create(userBadgeData);
|
||||||
|
|
||||||
@@ -265,8 +263,8 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockUserBadge);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockUserBadge);
|
||||||
couchdbService.updateDocument.mockResolvedValue({
|
mockCouchdbService.updateDocument.mockResolvedValue({
|
||||||
...mockUserBadge,
|
...mockUserBadge,
|
||||||
earnedAt: '2023-11-02T10:00:00.000Z',
|
earnedAt: '2023-11-02T10:00:00.000Z',
|
||||||
_rev: '2-def',
|
_rev: '2-def',
|
||||||
@@ -296,7 +294,7 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findDocumentById.mockResolvedValue(mockUserBadge);
|
mockCouchdbService.findDocumentById.mockResolvedValue(mockUserBadge);
|
||||||
|
|
||||||
const userBadge = await UserBadge.findById('user_badge_123');
|
const userBadge = await UserBadge.findById('user_badge_123');
|
||||||
expect(userBadge).toBeDefined();
|
expect(userBadge).toBeDefined();
|
||||||
@@ -306,7 +304,7 @@ describe('UserBadge Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when user badge not found', async () => {
|
it('should return null when user badge not found', async () => {
|
||||||
couchdbService.findDocumentById.mockResolvedValue(null);
|
mockCouchdbService.findDocumentById.mockResolvedValue(null);
|
||||||
|
|
||||||
const userBadge = await UserBadge.findById('nonexistent');
|
const userBadge = await UserBadge.findById('nonexistent');
|
||||||
expect(userBadge).toBeNull();
|
expect(userBadge).toBeNull();
|
||||||
@@ -336,7 +334,7 @@ describe('UserBadge Model', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
couchdbService.findByType.mockResolvedValue(mockUserBadges);
|
mockCouchdbService.findByType.mockResolvedValue(mockUserBadges);
|
||||||
|
|
||||||
const userBadges = await UserBadge.findByUser('user_123');
|
const userBadges = await UserBadge.findByUser('user_123');
|
||||||
expect(userBadges).toHaveLength(2);
|
expect(userBadges).toHaveLength(2);
|
||||||
@@ -368,7 +366,7 @@ describe('UserBadge Model', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
couchdbService.findByType.mockResolvedValue(mockUserBadges);
|
mockCouchdbService.findByType.mockResolvedValue(mockUserBadges);
|
||||||
|
|
||||||
const userBadges = await UserBadge.findByBadge('badge_123');
|
const userBadges = await UserBadge.findByBadge('badge_123');
|
||||||
expect(userBadges).toHaveLength(2);
|
expect(userBadges).toHaveLength(2);
|
||||||
@@ -390,17 +388,17 @@ describe('UserBadge Model', () => {
|
|||||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||||
};
|
};
|
||||||
|
|
||||||
couchdbService.findByType.mockResolvedValue([mockUserBadge]);
|
mockCouchdbService.findByType.mockResolvedValue([mockUserBadge]);
|
||||||
|
|
||||||
const hasBadge = await UserBadge.userHasBadge('user_123', 'badge_123');
|
const hasBadge = await UserBadge.userHasBadge('user_123', 'badge_123');
|
||||||
expect(hasBadge).toBe(true);
|
expect(hasBadge).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if user does not have specific badge', async () => {
|
it('should return false if user does not have specific badge', async () => {
|
||||||
couchdbService.findByType.mockResolvedValue([]);
|
mockCouchdbService.findByType.mockResolvedValue([]);
|
||||||
|
|
||||||
const hasBadge = await UserBadge.userHasBadge('user_123', 'badge_456');
|
const hasBadge = await UserBadge.userHasBadge('user_123', 'badge_456');
|
||||||
expect(hasBadge).toBe(false);
|
expect(hasBadge).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+1169
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user