-
Notifications
You must be signed in to change notification settings - Fork 37
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 #1589 from demergent-labs/fs_tests
Fs tests
- Loading branch information
Showing
27 changed files
with
7,308 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
.azle | ||
.dfx | ||
node_modules |
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,12 @@ | ||
{ | ||
"canisters": { | ||
"apollo_server": { | ||
"type": "custom", | ||
"main": "src/index.ts", | ||
"candid": "src/index.did", | ||
"build": "npx azle apollo_server", | ||
"wasm": ".azle/apollo_server/apollo_server.wasm", | ||
"gzip": true | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
{ | ||
"scripts": { | ||
"pretest": "ts-node --transpile-only --ignore=false test/pretest.ts", | ||
"test": "ts-node --transpile-only --ignore=false test/test.ts" | ||
}, | ||
"dependencies": { | ||
"@apollo/server": "^4.10.0", | ||
"azle": "0.19.0", | ||
"express": "^4.18.2", | ||
"graphql": "^16.8.1" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.21", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,4 @@ | ||
service: () -> { | ||
http_request: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:record {arbitrary_data:text}; callback:func (text) -> (record {token:opt record {arbitrary_data:text}; body:vec nat8}) query}}; status_code:nat16}) query; | ||
http_request_update: (record {url:text; method:text; body:vec nat8; headers:vec record {text; text}; certificate_version:opt nat16}) -> (record {body:vec nat8; headers:vec record {text; text}; upgrade:opt bool; streaming_strategy:opt variant {Callback:record {token:record {arbitrary_data:text}; callback:func (text) -> (record {token:opt record {arbitrary_data:text}; body:vec nat8}) query}}; status_code:nat16}); | ||
} |
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,102 @@ | ||
// TODO once we have dfx 0.16.x working reenable these tests in CI | ||
|
||
import { Server } from 'azle'; | ||
import { ApolloServer } from '@apollo/server'; | ||
import { expressMiddleware } from '@apollo/server/express4'; | ||
import express from 'express'; | ||
|
||
// A schema is a collection of type definitions (hence "typeDefs") | ||
// that together define the "shape" of queries that are executed against | ||
// your data. | ||
const typeDefs = `#graphql | ||
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol. | ||
# This "Book" type defines the queryable fields for every book in our data source. | ||
type Book { | ||
id: String | ||
title: String | ||
rating: Int | ||
} | ||
type Author { | ||
id: String | ||
name: String | ||
} | ||
# The "Query" type is special: it lists all of the available queries that | ||
# clients can execute, along with the return type for each. In this | ||
# case, the "books" query returns an array of zero or more Books (defined above). | ||
type Query { | ||
books: [Book] | ||
authors: [Author] | ||
titles: [String] | ||
} | ||
type Mutation { | ||
createBook(title: String!, rating: Int!): Book | ||
} | ||
`; | ||
|
||
let books = [ | ||
{ | ||
id: '0', | ||
title: 'The Awakening', | ||
rating: 34 | ||
}, | ||
{ | ||
id: '1', | ||
title: 'City of Glass', | ||
rating: 63 | ||
} | ||
]; | ||
|
||
const authors = [ | ||
{ | ||
id: '0', | ||
name: 'Jordan' | ||
}, | ||
{ | ||
id: '1', | ||
name: 'Ben' | ||
} | ||
]; | ||
|
||
// Resolvers define how to fetch the types defined in your schema. | ||
// This resolver retrieves books from the "books" array above. | ||
const resolvers = { | ||
Query: { | ||
books: () => books, | ||
authors: () => authors, | ||
titles: () => { | ||
return books.map((book) => book.title); | ||
} | ||
}, | ||
Mutation: { | ||
createBook: (parent: any, args: any) => { | ||
const book = { | ||
id: books.length.toString(), | ||
title: args.title, | ||
rating: args.rating | ||
}; | ||
|
||
books = [...books, book]; | ||
|
||
return book; | ||
} | ||
} | ||
}; | ||
|
||
export default Server(async () => { | ||
const app = express(); | ||
|
||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers | ||
}); | ||
|
||
await server.start(); | ||
|
||
app.use(express.json({ limit: '50mb' }), expressMiddleware(server, {})); | ||
|
||
return app.listen(); | ||
}); |
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,15 @@ | ||
import { execSync } from 'child_process'; | ||
|
||
async function pretest() { | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
|
||
execSync(`dfx canister uninstall-code apollo_server || true`, { | ||
stdio: 'inherit' | ||
}); | ||
|
||
execSync(`dfx deploy`, { | ||
stdio: 'inherit' | ||
}); | ||
} | ||
|
||
pretest(); |
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,6 @@ | ||
import { getCanisterId, runTests } from 'azle/test'; | ||
import { getTests } from './tests'; | ||
|
||
const canisterId = getCanisterId('apollo_server'); | ||
|
||
runTests(getTests(canisterId)); |
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,74 @@ | ||
import * as dns from 'node:dns'; | ||
dns.setDefaultResultOrder('ipv4first'); | ||
|
||
import { Test } from 'azle/test'; | ||
|
||
export function getTests(canisterId: string): Test[] { | ||
const origin = `http://${canisterId}.localhost:8000`; | ||
|
||
return [ | ||
{ | ||
name: 'query books', | ||
test: async () => { | ||
try { | ||
const response = await fetch(origin, { | ||
method: 'POST', | ||
headers: [['Content-Type', 'application/json']], | ||
body: JSON.stringify({ | ||
query: ` | ||
query { | ||
books { | ||
id | ||
title | ||
} | ||
} | ||
` | ||
}) | ||
}); | ||
const responseJson = await response.json(); | ||
|
||
return { | ||
Ok: | ||
responseJson.data.books.length === 2 && | ||
responseJson.data.books[0].title === 'The Awakening' | ||
}; | ||
} catch (error: any) { | ||
return { | ||
Err: error | ||
}; | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'query authors', | ||
test: async () => { | ||
try { | ||
const response = await fetch(origin, { | ||
method: 'POST', | ||
headers: [['Content-Type', 'application/json']], | ||
body: JSON.stringify({ | ||
query: ` | ||
query { | ||
authors { | ||
name | ||
} | ||
} | ||
` | ||
}) | ||
}); | ||
const responseJson = await response.json(); | ||
|
||
return { | ||
Ok: | ||
responseJson.data.authors.length === 2 && | ||
responseJson.data.authors[0].name === 'Jordan' | ||
}; | ||
} catch (error: any) { | ||
return { | ||
Err: error | ||
}; | ||
} | ||
} | ||
} | ||
]; | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "ES2020", | ||
"moduleResolution": "node", | ||
"allowJs": true, | ||
"outDir": "HACK_BECAUSE_OF_ALLOW_JS", | ||
"allowSyntheticDefaultImports": true | ||
} | ||
} |
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,3 @@ | ||
.azle | ||
.dfx | ||
node_modules |
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,12 @@ | ||
{ | ||
"canisters": { | ||
"fs": { | ||
"type": "custom", | ||
"main": "src/index.ts", | ||
"candid": "src/index.did", | ||
"build": "npx azle fs", | ||
"wasm": ".azle/fs/fs.wasm", | ||
"gzip": true | ||
} | ||
} | ||
} |
Oops, something went wrong.