Skip to content

Commit

Permalink
Add tests (#38)
Browse files Browse the repository at this point in the history
* add GA

* add Jest

* Add mutation and Query tests.

* Fix URL

* add teardown
  • Loading branch information
MichelDiz authored Oct 7, 2023
1 parent c4ac383 commit 01f2d05
Show file tree
Hide file tree
Showing 14 changed files with 11,776 additions and 3,067 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Docker Compose
run: docker-compose -f docker-compose.test.yml build

- name: Run Tests
run: docker-compose -f docker-compose.test.yml run app
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:20

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn install

COPY . .

CMD ["yarn", "test"]
22 changes: 22 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'
services:
app:
build: .
depends_on:
- dgraph-alpha
environment:
- RUNNING_JEST=true
dgraph-zero:
image: dgraph/dgraph:latest
ports:
- "5080:5080"
command: dgraph zero --my dgraph-zero:5080

dgraph-alpha:
image: dgraph/dgraph:latest
ports:
- "8080:8080"
- "9080:9080"
command: dgraph alpha --my dgraph-alpha:7080 --zero dgraph-zero:5080 --security "whitelist=0.0.0.0/0"
depends_on:
- dgraph-zero
24 changes: 12 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { ApolloServer, gql } from 'apollo-server-express';
import resolvers from './src/resolvers/index.ts';
import schemaDefinition from './src/schema/schemaAST.ts';

const defs = schemaDefinition()
const defs = schemaDefinition();
const app = express();

const typeDefs = gql`
${defs[0]}
`;

const _resolvers = resolvers(defs[1])[0]
const _resolvers = resolvers(defs[1])[0];

const server = new ApolloServer({ typeDefs, resolvers :_resolvers });
const server = new ApolloServer({ typeDefs, resolvers: _resolvers });

async function startServer() {
export async function startServer() {
await server.start();
server.applyMiddleware({ app, cors: false });
}

startServer().catch(err => console.error(err));
const port = 4001;

const port = 4001;
app.listen(port, () => {
console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`),
console.log('Use postman to test the API');
});
}

app.listen(port, () => {
console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`),
console.log('Use postman to test the API');
});
// TODO: Fix this later
// startServer().catch(err => console.error(err));
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
roots: ['<rootDir>/src/__tests__'],
testTimeout: 60000,
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
globalSetup: '<rootDir>/src/__tests__/setup.ts',
globalTeardown: '<rootDir>/src/__tests__/teardown.ts',
testPathIgnorePatterns: ["<rootDir>/src/__tests__/setup.ts", "<rootDir>/src/__tests__/teardown.ts"],
};
Loading

0 comments on commit 01f2d05

Please sign in to comment.