Skip to content

Commit

Permalink
Merge branch 'release/4.0.0-alpha.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobuddy committed Jun 18, 2024
2 parents 3728d28 + 081eb9c commit 2cc5ebc
Show file tree
Hide file tree
Showing 20 changed files with 411 additions and 94 deletions.
12 changes: 0 additions & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: mnfst
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
## Check list before submitting

- [ ] I have performed a self-review of my code (no debugs, no commented code, good naming, etc.)
- [ ] I wrote the relative tests
- [ ] I updated the documentation if necessary
- [ ] This PR is wrote in a clear language and correctly labeled
9 changes: 6 additions & 3 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ jobs:
- name: Install dependencies
run: npm ci
working-directory: ./packages/core/manifest
- name: Build app
- name: Build App
run: npm run build
working-directory: ./packages/core/manifest
- name: Test app
run: npm run test
- name: Run tests
run: npm run test:ci
working-directory: ./packages/core/manifest
- name: Run End-to-End tests
run: npm run test:e2e:ci
working-directory: ./packages/core/manifest
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<br>
</p>

> [!NOTE]
> Manifest is in the Proof of Concept phase. If this approach suits you, we will develop a stable version with the expected features. We rely on your feedback to understand which features you need.
[Manifest](https://manifest.build) is the simplest **BaaS (Backend As A Service)** you will find.

Here is an example of a complete Manifest app:
Expand Down
7 changes: 7 additions & 0 deletions packages/core/manifest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ Simply run this command on your terminal from the root of your project:
```bash
npx add-manifest
```

## Test

```bash
npm run test
npm run test:e2e
```
9 changes: 9 additions & 0 deletions packages/core/manifest/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Manifest End-2-End tests

This folder contains the End-2-End tests for the Manifest core package.

Run tests:

```bash
npm run test:e2e
```
14 changes: 14 additions & 0 deletions packages/core/manifest/e2e/assets/mock-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'mock-backend-for-e2e-tests'
entities:
Owner:
properties:
- name
- { name: email, type: email }

Dog:
properties:
- name
- { name: age, type: number }
- { name: birthdate, type: date }
belongsTo:
- Owner
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
},
"setupFilesAfterEnv": ["./jest.setup.ts"]
}
44 changes: 44 additions & 0 deletions packages/core/manifest/e2e/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Test, TestingModule } from '@nestjs/testing'
import { AppModule } from '../src/app.module'
import { YamlService } from '../src/manifest/services/yaml/yaml.service'
import { INestApplication } from '@nestjs/common'
import supertest from 'supertest'
import { load } from 'js-yaml'
import fs from 'fs'

let app: INestApplication

beforeAll(async () => {
// Set environment variables for testing.
process.env.NODE_ENV = 'test'
process.env.DB_DATABASE = ':memory:'
process.env.DB_DROP_SCHEMA = 'true'

// Start the NestJS application mocking some services.
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule]
})
.overrideProvider(YamlService)
.useValue({
load: () =>
load(
fs.readFileSync(
`${process.cwd()}/e2e/assets/mock-backend.yml`,
'utf8'
)
)
})
.compile()

app = moduleFixture.createNestApplication()

// Store request object in global scope to use in tests.
global.request = supertest(app.getHttpServer())

await app.init()
})

afterAll(async () => {
delete global.request
await app.close()
})
77 changes: 77 additions & 0 deletions packages/core/manifest/e2e/tests/crud.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Paginator, SelectOption } from '@mnfst/types'

describe('CRUD (e2e)', () => {
const dummyDog = {
name: 'Fido',
age: 5
}

it('POST /dynamic/:entity', async () => {
const response = await global.request.post('/dynamic/dogs').send(dummyDog)

expect(response.status).toBe(201)
})

it('GET /dynamic/:entity', async () => {
const response = await global.request.get('/dynamic/dogs')

expect(response.status).toBe(200)
expect(response.body).toMatchObject<Paginator<any>>({
data: expect.any(Array),
currentPage: expect.any(Number),
lastPage: expect.any(Number),
from: expect.any(Number),
to: expect.any(Number),
total: expect.any(Number),
perPage: expect.any(Number)
})
expect(response.body.data.length).toBe(1)
})

it('GET /dynamic/:entity/select-options', async () => {
const response = await global.request.get('/dynamic/dogs/select-options')

expect(response.status).toBe(200)
expect(response.body).toMatchObject<SelectOption[]>([
{
label: dummyDog.name,
id: 1
}
])
})

it('GET /dynamic/:entity/:id', async () => {
const response = await global.request.get('/dynamic/dogs/1')

expect(response.status).toBe(200)
expect(response.body).toMatchObject(dummyDog)
})

it('PUT /dynamic/:entity/:id', async () => {
const newName = 'Rex'

const response = await global.request.put('/dynamic/dogs/1').send({
name: newName
})

expect(response.status).toBe(200)

const updatedResponse = await global.request.get('/dynamic/dogs/1')

expect(updatedResponse.status).toBe(200)
expect(updatedResponse.body).toMatchObject({
...dummyDog,
name: newName
})
})

it('DELETE /dynamic/:entity/:id', async () => {
const response = await global.request.delete('/dynamic/dogs/1')

expect(response.status).toBe(200)

const updatedResponse = await global.request.get('/dynamic/dogs/1')

expect(updatedResponse.status).toBe(404)
})
})
8 changes: 8 additions & 0 deletions packages/core/manifest/e2e/tests/health.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe('Health (e2e)', () => {
it('GET /health', () => {
return global.request
.get('/health')
.expect(200)
.expect(JSON.stringify({ status: 'OK' }))
})
})
38 changes: 38 additions & 0 deletions packages/core/manifest/e2e/tests/manifest.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { EntityManifest } from '@mnfst/types'

describe('Manifest (e2e)', () => {
it('GET /manifest', async () => {
const response = await global.request.get('/manifest')

expect(response.status).toBe(200)
expect(response.body).toMatchObject({
name: expect.any(String),
entities: expect.any(Object)
})

expect(Object.keys(response.body.entities).length).toBeGreaterThan(0)

Object.values(response.body.entities).forEach((entity: EntityManifest) => {
expect(entity).toMatchObject<Partial<EntityManifest>>({
properties: expect.any(Array)
})

if (entity.belongsTo !== undefined) {
expect(entity.belongsTo).toEqual(expect.any(Array))
}
})
})

it('GET /manifest/entities/:slug', async () => {
const response = await global.request.get('/manifest/entities/dogs')

expect(response.status).toBe(200)
expect(response.body).toMatchObject<Partial<EntityManifest>>({
properties: expect.any(Array)
})

if (response.body.belongsTo !== undefined) {
expect(response.body.belongsTo).toEqual(expect.any(Array))
}
})
})
Loading

0 comments on commit 2cc5ebc

Please sign in to comment.