Newer
Older
import { HttpModule } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationModule } from '../configuration/configuration.module';
import { PostsController } from './posts.controller';
import { PostsService } from './posts.service';
import { PostWithMeta } from './schemas/postWithMeta.schema';
describe('PostsController', () => {
let controller: PostsController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigurationModule, HttpModule],
providers: [PostsService],
controllers: [PostsController],
}).compile();
controller = module.get<PostsController>(PostsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('should get pending attachments', async () => {
const result:PostWithMeta = {posts:[], meta:{pagination: null}};
const query = "";
jest.spyOn(controller, 'findAll').mockImplementation(async (): Promise<any> => result);
expect(await controller.findAll(query)).toBe(result);
});
it('should get pending attachments', async () => {
const result = { posts:[] };
jest.spyOn(controller, 'findAllTags').mockImplementation(async (): Promise<any> => result);
expect(await controller.findAllTags()).toBe(result);
});
it('should get pending attachments', async () => {
const result = { public:[], comune:[], others:[] };
const id = "78945945"
jest.spyOn(controller, 'getPostbyId').mockImplementation(async (): Promise<any> => result);
expect(await controller.getPostbyId(id)).toBe(result);
});