Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New organization for e2e specs #12

Merged
merged 9 commits into from
Jul 12, 2024
7 changes: 7 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Proposal

Hello world!

## How do test it?

Try say hello world.
2 changes: 1 addition & 1 deletion .github/workflows/dev-specs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI-Specs

on: [push, pull_request]
on: [push]

jobs:
specs-dev:
Expand Down
163 changes: 0 additions & 163 deletions specs/entity.e2e.spec.ts

This file was deleted.

22 changes: 22 additions & 0 deletions specs/entity/delete.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import request from 'supertest';
import { app } from '../global'
import { createEntity } from '../helpers';

describe('DELETE /entity/:id', () => {
test('should delete', async () => {
const entity = await createEntity()
await request(app)
.delete(`/entity/${entity.id}`)
.expect(204)
})
test('should reject invalid id', async () => {
await request(app)
.delete('/entity/invalid')
.expect(400)
})
test('should reject non existent id', async () => {
await request(app)
.delete('/entity/999999')
.expect(404)
})
})
64 changes: 64 additions & 0 deletions specs/entity/get.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import request from 'supertest';
import { app } from '../global'
import { createEntity } from '../helpers';

test('GET /entity', async () => {
await request(app)
.get('/entity?page=1&perPage=10')
.expect(200)
.expect({
page: 1,
perPage: 10,
totalPages: 1,
entries: []
})
})

test('GET /entity with data', async () => {
await Promise.all(Array.from({ length: 20 }, createEntity))
const response = await request(app)
.get('/entity?page=1&perPage=10')
expect(response.status).toEqual(200)
expect(response.body.page).toEqual(1)
expect(response.body.perPage).toEqual(10)
expect(response.body.totalPages).toEqual(2)

const response2 = await request(app)
.get('/entity?page=1&perPage=20')
expect(response2.status).toEqual(200)
expect(response2.body.page).toEqual(1)
expect(response2.body.perPage).toEqual(20)
})

test('GET /entity without page and perPage', async () => {
await request(app)
.get('/entity')
.expect(400)
})

test('GET /entity with invalid page and perPage', async () => {
await request(app)
.get('/entity?page=invalid&perPage=invalid')
.expect(400)
})

test('GET /entity/:id', async () => {
const entity = await createEntity()
const response = await request(app)
.get(`/entity/${entity.id}`)

expect(response.status).toEqual(200)
expect(response.body.title).toEqual(entity.title)
})

test('GET /entity/:id with invalid id', async () => {
await request(app)
.get('/entity/invalid')
.expect(400)
})

test('GET /entity/:id with non existent id', async () => {
await request(app)
.get('/entity/999999')
.expect(404)
})
50 changes: 50 additions & 0 deletions specs/entity/post.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import request from 'supertest';
import { app } from '../global'

describe('POST /entity', () => {
test('should create', async () => {
const entity = {
"title": "foo",
"properties": {
"strength": 10
},
"description": "Lorem lorem lorem",
"author": "John Doe",
"image": {
"src": "url",
"alt": "alt"
},
"sections": "markdown content",
"type": "item"
}
const response = await request(app)
.post('/entity')
.send(entity)

expect(response.statusCode).toEqual(201)
expect(response.body).toEqual(entity)
})
test('should reject invalid entity', async () => {
await request(app)
.post('/entity')
.send({})
.expect(400)
})
test('should reject entity with invalid properties', async () => {
await request(app)
.post('/entity')
.send({
"title": 1,
"properties": "invalid",
"description": "Lorem lorem lorem",
"author": "John Doe",
"image": {
"src": "url",
"alt": "alt"
},
"sections": "markdown content",
"type": "item"
})
.expect(400)
})
})
32 changes: 32 additions & 0 deletions specs/entity/put.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import request from 'supertest';
import { app } from '../global'
import { createEntity } from '../helpers';

describe('PUT /entity/:id', () => {
test('should update', async () => {
const entity = await createEntity()
const update = {
"title": "foo 777"
}

const updateResponse = await request(app)
.put(`/entity/${entity.id}`)
.send(update)

expect(updateResponse.status).toEqual(204)

const entityUpdated = await request(app).get(`/entity/${entity.id}`)

expect(entityUpdated.body.title).toEqual("foo 777")
})
test('should reject invalid id', async () => {
await request(app)
.put('/entity/invalid')
.expect(400)
})
test('should reject non existent id', async () => {
await request(app)
.put('/entity/999999')
.expect(404)
})
})
4 changes: 4 additions & 0 deletions specs/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import WebCore from '../src/web/core';
import express from 'express';

export const app = new WebCore(3000, express()).app;
3 changes: 2 additions & 1 deletion specs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LogModel } from '../src/models/logs/log.model';
import * as bcrypt from 'bcrypt'

export const createEntity = async () => {
await EntityModel.sync({ force: true })
const createdEntity = await EntityModel.create({
"title": faker.string.uuid(),
"properties": {
Expand Down Expand Up @@ -40,7 +41,7 @@ export const findUser = async (id: number) => {
return foundUser as unknown as User | null
}

export const createLog = async (customType = null) => {
export const createLog = async (customType: null | any = null) => {
const createdLog = await LogModel.create({
"type": customType || faker.string.uuid(),
"content": "test"
Expand Down
8 changes: 2 additions & 6 deletions specs/logs.e2e.spec.ts → specs/logs/get.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import request from 'supertest'
import express from 'express'
import WebCore from "../src/web/core";
import { createLog } from './helpers';


const app = new WebCore(3000, express()).app
import { app } from '../global'
import { createLog } from '../helpers';


test('GET /log', async () => {
Expand Down
Loading