mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
getContent test passes
This commit is contained in:
parent
ea656fe9c7
commit
b20f33500e
1 changed files with 39 additions and 15 deletions
|
|
@ -6,7 +6,8 @@ console.log('db:', db); // Debugging line
|
||||||
console.log('db.getConnection:', db.getConnection); // Debugging line
|
console.log('db.getConnection:', db.getConnection); // Debugging line
|
||||||
|
|
||||||
describe('Folders', () => {
|
describe('Folders', () => {
|
||||||
const folder = new Folder(db, new Quiz(db));
|
const quiz = new Quiz(db);
|
||||||
|
const folder = new Folder(db, quiz);
|
||||||
let database;
|
let database;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|
@ -112,23 +113,46 @@ describe('Folders', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// // getOwner
|
// write a test for getContent
|
||||||
// describe('getOwner', () => {
|
describe('getContent', () => {
|
||||||
// it('should return the owner of a folder', async () => {
|
it('should return the content of a folder', async () => {
|
||||||
// const folderId = '60c72b2f9b1d8b3a4c8e4d3b';
|
|
||||||
// const userId = '12345';
|
|
||||||
|
|
||||||
// // Mock the database response
|
// create a new folder
|
||||||
// collection.findOne.mockResolvedValue({ userId });
|
const folderId = await folder.create('Test Folder', '12345');
|
||||||
|
|
||||||
// const result = await folders.getOwner(folderId);
|
// Insert the content using the quiz API
|
||||||
|
const _quiz1ObjectId = await quiz.create('Quiz 1', [], folderId.toString(), '12345');
|
||||||
|
const _quiz2ObjectId = await quiz.create('Quiz 2', [], folderId.toString(), '12345');
|
||||||
|
|
||||||
// expect(db.connect).toHaveBeenCalled();
|
const content = [
|
||||||
// expect(db.collection).toHaveBeenCalledWith('folders');
|
{ title: 'Quiz 1', content: [], _id: _quiz1ObjectId, created_at: expect.any(Date), updated_at: expect.any(Date), folderId: folderId.toString(), userId: '12345' },
|
||||||
// expect(collection.findOne).toHaveBeenCalledWith({ _id: new ObjectId(folderId) });
|
{ title: 'Quiz 2', content: [], _id: _quiz2ObjectId, created_at: expect.any(Date), updated_at: expect.any(Date), folderId: folderId.toString(), userId: '12345' },
|
||||||
// expect(result).toBe(userId);
|
];
|
||||||
// });
|
|
||||||
// });
|
const result = await folder.getContent(folderId.toString());
|
||||||
|
|
||||||
|
expect(result).toEqual(content);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
await database.collection('files').deleteMany({ folderId: folderId.toString() });
|
||||||
|
await database.collection('folders').deleteMany({ _id: folderId });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty array if the folder has no content', async () => {
|
||||||
|
// create a new folder
|
||||||
|
const folderId = await folder.create('Test Folder', '12345');
|
||||||
|
|
||||||
|
const content = [];
|
||||||
|
const result = await folder.getContent(folderId.toString());
|
||||||
|
|
||||||
|
expect(result).toEqual(content);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
await database.collection('folders').deleteMany({ _id: folderId });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // write a test for getContent
|
// // write a test for getContent
|
||||||
// describe('getContent', () => {
|
// describe('getContent', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue