Skip to content

Commit

Permalink
fix api test
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Oct 24, 2023
1 parent 73595f4 commit ace6d5c
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ import {
columnBoardNodeFactory,
columnNodeFactory,
courseFactory,
submissionContainerElementFactory,

Check failure on line 11 in apps/server/src/modules/board/controller/api-test/content-element-create.api.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'submissionContainerElementFactory' is defined but never used
submissionContainerElementNodeFactory,
submissionItemFactory,

Check failure on line 13 in apps/server/src/modules/board/controller/api-test/content-element-create.api.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'submissionItemFactory' is defined but never used
submissionItemNodeFactory,
TestApiClient,
UserAndAccountTestFactory,
} from '@shared/testing';
import { ServerTestModule } from '@modules/server/server.module';
import { AnyContentElementResponse, SubmissionContainerElementResponse } from '../dto';

const baseRouteName = '/cards';
const submissionRouteName = '/board-submissions';

describe(`content element create (api)`, () => {
let app: INestApplication;
let em: EntityManager;
let testApiClient: TestApiClient;
let testApiClientSubmission: TestApiClient;

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -30,6 +36,7 @@ describe(`content element create (api)`, () => {
await app.init();
em = module.get(EntityManager);
testApiClient = new TestApiClient(app, baseRouteName);
testApiClientSubmission = new TestApiClient(app, submissionRouteName);
});

afterAll(async () => {
Expand Down Expand Up @@ -143,22 +150,33 @@ describe(`content element create (api)`, () => {
await cleanupCollections(em);

const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher();
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();

const course = courseFactory.build({ teachers: [teacherUser] });
await em.persistAndFlush([teacherAccount, teacherUser, course]);
const course = courseFactory.build({ teachers: [teacherUser], students: [studentUser] });

await em.persistAndFlush([teacherAccount, teacherUser, studentAccount, studentUser, course]);

const columnBoardNode = columnBoardNodeFactory.buildWithId({
context: { id: course.id, type: BoardExternalReferenceType.Course },
});
const columnNode = columnNodeFactory.buildWithId({ parent: columnBoardNode });
const cardNode = cardNodeFactory.buildWithId({ parent: columnNode });
const submissionContainerNode = columnNodeFactory.buildWithId({ parent: cardNode });
const submissionItemNode = cardNodeFactory.buildWithId({ parent: submissionContainerNode });
const submissionElementContainerNode = submissionContainerElementNodeFactory.buildWithId({ parent: cardNode });
const submissionItemNode = submissionItemNodeFactory.buildWithId({
parent: submissionElementContainerNode,
userId: studentUser.id,
});

await em.persistAndFlush([columnBoardNode, columnNode, cardNode, submissionContainerNode, submissionItemNode]);
await em.persistAndFlush([
columnBoardNode,
columnNode,
cardNode,
submissionElementContainerNode,
submissionItemNode,
]);
em.clear();

const loggedInClient = await testApiClient.login(teacherAccount);
const loggedInClient = await testApiClientSubmission.login(studentAccount);

return { loggedInClient, cardNode, submissionItemNode };
};
Expand Down Expand Up @@ -192,6 +210,16 @@ describe(`content element create (api)`, () => {

expect((response.body as AnyContentElementResponse).type).toEqual(ContentElementType.FILE);
});

it('should throw if element is not RICH_TEXT or FILE', async () => {
const { loggedInClient, submissionItemNode } = await setup();

const response = await loggedInClient.post(`${submissionItemNode.id}/elements`, {
type: ContentElementType.EXTERNAL_TOOL,
});

expect(response.statusCode).toEqual(400);
});
});
});

Expand Down

0 comments on commit ace6d5c

Please sign in to comment.