-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from TravisFrankMTG/tests
Tests + Id Fix
- Loading branch information
Showing
16 changed files
with
396 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
POSTGRES_URI=postgres://zjxjnswd:[email protected]:5432/zjxjnswd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
demo/dump.rdb | ||
.DS_Store | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: required | ||
services: | ||
- docker | ||
before_install: | ||
- docker build -t open-source-labs/obsidian . | ||
script: | ||
- docker run open-source-labs/obsidian test --allow-net --allow-read --allow-env --unstable deno.test.ts | ||
env: | ||
global: | ||
secure: sfaHXoKGXnAkwS/QK2pdTPC1NVqd9+pVWImEcz8W9IXFRsOcHpt9lVsmB0dFvDpVm+9KFpcBwnpfOtiyoj6Q9NGIY71jG58kYHdbcWBlR3onS7/JBvgEu94DC7HZR+rQ4/GW+ROh4avBt6RjDSuLk4qQ73Yc3+SDKAl+M0PTADlVZpkicCID59qcdynbAjXu5W8lW2Hp0hqO72Prx/8hgmchI0I7zSYcPBFSy3WaEPJa52yKesVwsHcFtzOBMrDAdE+R028AzdBAXUoiqh6cTVeLSTL1jnIWbCBtfAROlTR82cZyo4c7PJxYyqT3mhRSZvBN/3hdW7+xMOzq6gmpmcl1UO2Q5i4xXEGnatfuzMVa/8SqJZoG2IFIWZ4mvelwufHVuLgF+6JvK2BKSpjFfSUGo0p9G0bMg+GHwRipTPIq1If3ELkflAM6QJwL7TritwtWzWXfAfoZ3KALdPTiFzJAKyQfFvSwWbfXqAgqZIbLjlzSgOJ4QKWD6CBksU7b4Oky6hr/+R+ZihzQLtWKkk/8cklEG/NJlknS2vPRG8xRRF7/C+vSFPrCkmsakPc8c1iGfai8J3Vc09Pg0UeShJDWkSQ6QP165ub6LEL5nz0Qzp0CD1sSQu5re5/M5ef9V69L2pdYhEj0RaZ241DF5efzYAgLI8SvMr5TcTr06+8= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM hayd/alpine-deno:1.3.0 | ||
|
||
EXPOSE 3000 | ||
|
||
WORKDIR /usr/app | ||
|
||
COPY . . | ||
|
||
CMD [ "run", "--unstable", "--allow-net", "--allow-env", "--allow-read", "testServer.ts", "-c", "tsconfig.json" ] | ||
|
||
# deno run --unstable --allow-net --allow-env --allow-read testServer.ts -c tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,20 +46,20 @@ Optimized for use in server-side rendered React apps built with Deno, full stack | |
In the server: | ||
|
||
```javascript | ||
import { ObsidianRouter } from 'https://deno.land/x/[email protected].0/mod.ts'; | ||
import { ObsidianRouter } from 'https://deno.land/x/[email protected].1/mod.ts'; | ||
``` | ||
|
||
In the app: | ||
In the app: | ||
|
||
```javascript | ||
import { ObsidianWrapper } from 'https://deno.land/x/[email protected].0/mod.ts'; | ||
import { ObsidianWrapper } from 'https://deno.land/x/[email protected].1/clientMod.ts'; | ||
``` | ||
|
||
## Creating the Router | ||
|
||
```javascript | ||
import { Application, Router } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
import { ObsidianRouter, gql } from 'https://deno.land/x/[email protected].0/mod.ts'; | ||
import { ObsidianRouter, gql } from 'https://deno.land/x/[email protected].1/mod.ts'; | ||
|
||
const PORT = 8000; | ||
|
||
|
@@ -131,7 +131,7 @@ app.use(router.routes(), router.allowedMethods()); | |
## Creating the Wrapper | ||
|
||
```javascript | ||
import { ObsidianWrapper } from 'https://deno.land/x/[email protected].0/mod.ts'; | ||
import { ObsidianWrapper } from 'https://deno.land/x/[email protected].1/clientMod.ts'; | ||
|
||
const App = () => { | ||
return ( | ||
|
@@ -145,7 +145,7 @@ const App = () => { | |
## Making a Query | ||
|
||
```javascript | ||
import { useObsidian } from 'https://deno.land/x/[email protected].0/mod.ts'; | ||
import { useObsidian } from 'https://deno.land/x/[email protected].1/clientMod.ts'; | ||
|
||
const WeatherApp = () => { | ||
const { gather } = useObsidian(); | ||
|
@@ -163,11 +163,15 @@ const WeatherApp = () => { | |
}; | ||
``` | ||
|
||
## Documentation | ||
|
||
[obsidian.land](http://obsidian.land) | ||
|
||
## Authors | ||
|
||
*Lascaux* Engineers | ||
|
||
[Alonso Garza](https://github.com/Alonsog66) | ||
[Burak Caliskan](https://github.com/CaliskanBurak) | ||
[Matt Meigs](https://github.com/mmeigs) | ||
[Travis Frank](https://github.com/TravisFrankMTG/) | ||
[Travis Frank](https://github.com/TravisFrankMTG/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { | ||
ObsidianWrapper, | ||
useObsidian, | ||
ObsidianClient, | ||
} from './ObsidianWrapper/ObsidianWrapper.jsx'; | ||
|
||
export { ObsidianWrapper, useObsidian, ObsidianClient }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { superoak } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
import { describe, it } from 'https://deno.land/x/[email protected]/test/utils.ts'; | ||
import { expect } from 'https://deno.land/x/[email protected]/test/deps.ts'; | ||
import { app } from './testServer.ts'; | ||
|
||
describe('GET request to root url', () => { | ||
it('Sends 200 Status and Content Type text/html', async (done) => { | ||
(await superoak(app)).get('/').end((err, res) => { | ||
expect(res.status).toEqual(200); | ||
expect(res.type).toEqual('text/html'); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: "3.8" | ||
|
||
services: | ||
site: | ||
build: . | ||
restart: always | ||
volumes: | ||
- ./:/usr/app | ||
ports: | ||
- 3000:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { superoak } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
import { describe, it } from 'https://deno.land/x/[email protected]/test/utils.ts'; | ||
import { expect } from 'https://deno.land/x/[email protected]/test/deps.ts'; | ||
import { app } from './testServer.ts'; | ||
|
||
describe('GraphQL query response testing', () => { | ||
it('getBook query succeeds', async (done: any) => { | ||
(await superoak(app)) | ||
.post('/graphql') | ||
.send({ query: '{getBook(id:1){ id title author }}' }) | ||
.end((err: any, res: any) => { | ||
// console.log(res); | ||
expect(res.status).toEqual(200); | ||
expect(res.body.data.getBook.id).toEqual('1'); | ||
expect(res.body.data.getBook.title).toEqual('Lets Go'); | ||
expect(res.body.data.getBook.author).toEqual('NotJehooo'); | ||
|
||
setTimeout(async () => { | ||
if (true) { | ||
// @ts-ignore | ||
const dbOps = await import('./src/dbOps.js'); | ||
dbOps.redis.close(); | ||
} | ||
done(); | ||
}, 2000); | ||
}); | ||
}); | ||
|
||
it('Invalid getBook query fails', async (done) => { | ||
(await superoak(app)) | ||
.post('/graphql') | ||
.send({ query: '{getBook{ id title author }}' }) | ||
.end((err, res) => { | ||
// console.log('error', err); | ||
// console.log(res); | ||
expect(res.status).toEqual(200); | ||
expect(res.body.errors).toBeTruthy(); | ||
setTimeout(async () => { | ||
if (true) { | ||
// @ts-ignore | ||
const dbOps = await import('./src/dbOps.js'); | ||
dbOps.redis.close(); | ||
} | ||
done(); | ||
}, 2000); | ||
}); | ||
}); | ||
|
||
it('getEightBooks succeeds', async (done) => { | ||
(await superoak(app)) | ||
.post('/graphql') | ||
.send({ query: '{getEightBooks(id:1){ id title author }}' }) | ||
.end((err, res) => { | ||
// console.log(res); | ||
expect(res.status).toEqual(200); | ||
expect(res.body.data.getEightBooks).toHaveLength(8); | ||
setTimeout(async () => { | ||
if (true) { | ||
// @ts-ignore | ||
const dbOps = await import('./src/dbOps.js'); | ||
dbOps.redis.close(); | ||
} | ||
done(); | ||
}, 2000); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Redis cache testing', () => { | ||
it('second query takes less than half time of first', async (done) => { | ||
let firstResTime: number; | ||
(await superoak(app)) | ||
.post('/graphql') | ||
.send({ query: '{getBook(id:2){ id title author }}' }) | ||
.end((err, res) => { | ||
// console.log(res); | ||
firstResTime = Number(res.header['x-response-time'].slice(0, -2)); | ||
}); | ||
|
||
setTimeout(async () => { | ||
(await superoak(app)) | ||
.post('/graphql') | ||
.send({ query: '{getBook(id:2){ id title author }}' }) | ||
.end((err, res) => { | ||
const newTime: number = Number(res.header['x-response-time'].slice(0, -2)); | ||
|
||
console.log('firstTime', firstResTime); | ||
console.log('newTime', newTime); | ||
|
||
expect(newTime < firstResTime).toBeTruthy(); | ||
setTimeout(async () => { | ||
if (true) { | ||
// @ts-ignore | ||
const dbOps = await import('./src/dbOps.js'); | ||
dbOps.redis.close(); | ||
} | ||
done(); | ||
}, 1000); | ||
}); | ||
if (true) { | ||
// @ts-ignore | ||
const dbOps = await import('./src/dbOps.js'); | ||
dbOps.redis.close(); | ||
} | ||
}, 1000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
import { | ||
ObsidianWrapper, | ||
useObsidian, | ||
ObsidianClient, | ||
} from './ObsidianWrapper/ObsidianWrapper.jsx'; | ||
import { ObsidianRouter } from './src/obsidian.ts'; | ||
import gql from 'https://deno.land/x/[email protected]/graphql-tag/index.ts'; | ||
|
||
export { ObsidianWrapper, useObsidian, ObsidianClient, ObsidianRouter, gql }; | ||
export { ObsidianRouter, gql }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Client } from "https://deno.land/x/postgres/mod.ts"; | ||
import { config } from "https://deno.land/x/dotenv/mod.ts"; | ||
|
||
// Create a new client | ||
const uri = config().POSTGRES_URI; | ||
const client = new Client(uri); | ||
|
||
// Connect it | ||
await client.connect(); | ||
|
||
export default client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.