Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Dec 1, 2021
1 parent 3f420c9 commit 721ecee
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 128 deletions.
6 changes: 3 additions & 3 deletions packages/js/plugins/http/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = {
"^.+\\.(ts|tsx)$": "ts-jest"
},
modulePathIgnorePatterns: [
"<rootDir>/src/__tests__/e2e/integration"
"<rootDir>/src/__tests__/e2e/integration/"
],
testPathIgnorePatterns: [
"<rootDir>/src/__tests__/e2e/integration"
"<rootDir>/src/__tests__/e2e/integration/"
],
transformIgnorePatterns: [
"<rootDir>/src/__tests__/e2e/integration"
"<rootDir>/src/__tests__/e2e/integration/"
],
testEnvironment: 'node'
}
125 changes: 0 additions & 125 deletions packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { httpPlugin } from "../..";
import { Response } from "../../w3";

import { Web3ApiClient } from "@web3api/client-js"
import { ensPlugin } from "@web3api/ens-plugin-js";
import { ipfsPlugin } from "@web3api/ipfs-plugin-js";
import { ethereumPlugin } from "@web3api/ethereum-plugin-js";
import {
initTestEnvironment,
stopTestEnvironment,
buildAndDeployApi
} from "@web3api/test-env-js";
import axios from "axios";
import nock from "nock";

jest.setTimeout(360000)
Expand Down Expand Up @@ -274,120 +265,4 @@ describe("e2e tests for HttpPlugin", () => {
});

});

describe("integration", () => {

let client: Web3ApiClient;
let uri: string;
let ensAddress: string;

beforeAll(async () => {
const { ethereum, ipfs } = await initTestEnvironment();
const { data } = await axios.get("http://localhost:4040/deploy-ens");

ensAddress = data.ensAddress

client = new Web3ApiClient({
plugins: [
{
uri: "w3://ens/http.web3api.eth",
plugin: httpPlugin(),
},
{
uri: "w3://ens/ethereum.web3api.eth",
plugin: ethereumPlugin({
networks: {
testnet: {
provider: ethereum
}
},
defaultNetwork: "testnet"
}),
},
{
uri: "w3://ens/ipfs.web3api.eth",
plugin: ipfsPlugin({
provider: ipfs,
fallbackProviders: ["https://ipfs.io"]
})
},
{
uri: "w3://ens/ens.web3api.eth",
plugin: ensPlugin({
addresses: {
testnet: ensAddress
}
})
}
],
});

const api = await buildAndDeployApi(
`${__dirname}/integration`,
ipfs,
ensAddress
);

uri = `ens/testnet/${api.ensDomain}`;
});

afterAll(async () => {
await stopTestEnvironment();
});

it("get", async () => {
nock("http://www.example.com", { reqheaders: { 'X-Request-Header': "req-foo" } })
.defaultReplyHeaders(defaultReplyHeaders)
.get("/api")
.query({ query: "foo" })
.reply(200, '{data: "test-response"}', { 'X-Response-Header': "resp-foo" })

const response = await client.query<{ get: Response }>({
uri,
query: `query {
get(
url: "http://www.example.com/api"
request: {
responseType: TEXT
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}`
});

expect(response.data).toBeDefined()
expect(response.errors).toBeUndefined()
expect(response.data?.get.status).toBe(200)
});

it("post", async () => {
nock("http://www.example.com", { reqheaders: { 'X-Request-Header': "req-foo" } })
.defaultReplyHeaders(defaultReplyHeaders)
.post("/api", "{data: 'test-request'}")
.query({ query: "foo" })
.reply(200, '{data: "test-response"}', { 'X-Response-Header': "resp-foo" })

const response = await client.query<{ post: Response }>({
uri,
query: `query {
post(
url: "http://www.example.com/api"
request: {
responseType: TEXT
body: "{data: 'test-request'}"
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}`
});

expect(response.data).toBeTruthy();
expect(response.errors).toBeFalsy();

expect(response.data?.post.status).toBe(200);
expect(response.data?.post.body).toBeTruthy();
});
});
});
140 changes: 140 additions & 0 deletions packages/js/plugins/http/src/__tests__/e2e/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { httpPlugin } from "../..";
import { Response } from "../../w3";

import { Web3ApiClient } from "@web3api/client-js"
import { ensPlugin } from "@web3api/ens-plugin-js";
import { ipfsPlugin } from "@web3api/ipfs-plugin-js";
import { ethereumPlugin } from "@web3api/ethereum-plugin-js";
import {
initTestEnvironment,
stopTestEnvironment,
buildAndDeployApi
} from "@web3api/test-env-js";
import axios from "axios";
import nock from "nock";

jest.setTimeout(360000)

const defaultReplyHeaders = {
'access-control-allow-origin': '*',
'access-control-allow-credentials': 'true'
}

describe("e2e tests for HttpPlugin", () => {

describe("integration", () => {

let client: Web3ApiClient;
let uri: string;
let ensAddress: string;

beforeAll(async () => {
const { ethereum, ipfs } = await initTestEnvironment();
const { data } = await axios.get("http://localhost:4040/deploy-ens");

ensAddress = data.ensAddress

client = new Web3ApiClient({
plugins: [
{
uri: "w3://ens/http.web3api.eth",
plugin: httpPlugin(),
},
{
uri: "w3://ens/ethereum.web3api.eth",
plugin: ethereumPlugin({
networks: {
testnet: {
provider: ethereum
}
},
defaultNetwork: "testnet"
}),
},
{
uri: "w3://ens/ipfs.web3api.eth",
plugin: ipfsPlugin({
provider: ipfs,
fallbackProviders: ["https://ipfs.io"]
})
},
{
uri: "w3://ens/ens.web3api.eth",
plugin: ensPlugin({
addresses: {
testnet: ensAddress
}
})
}
],
});

const api = await buildAndDeployApi(
`${__dirname}/integration`,
ipfs,
ensAddress
);

uri = `ens/testnet/${api.ensDomain}`;
});

afterAll(async () => {
await stopTestEnvironment();
});

it("get", async () => {
nock("http://www.example.com", { reqheaders: { 'X-Request-Header': "req-foo" } })
.defaultReplyHeaders(defaultReplyHeaders)
.get("/api")
.query({ query: "foo" })
.reply(200, '{data: "test-response"}', { 'X-Response-Header': "resp-foo" })

const response = await client.query<{ get: Response }>({
uri,
query: `query {
get(
url: "http://www.example.com/api"
request: {
responseType: TEXT
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}`
});

expect(response.data).toBeDefined()
expect(response.errors).toBeUndefined()
expect(response.data?.get.status).toBe(200)
});

it("post", async () => {
nock("http://www.example.com", { reqheaders: { 'X-Request-Header': "req-foo" } })
.defaultReplyHeaders(defaultReplyHeaders)
.post("/api", "{data: 'test-request'}")
.query({ query: "foo" })
.reply(200, '{data: "test-response"}', { 'X-Response-Header': "resp-foo" })

const response = await client.query<{ post: Response }>({
uri,
query: `query {
post(
url: "http://www.example.com/api"
request: {
responseType: TEXT
body: "{data: 'test-request'}"
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}`
});

expect(response.data).toBeTruthy();
expect(response.errors).toBeFalsy();

expect(response.data?.post.status).toBe(200);
expect(response.data?.post.body).toBeTruthy();
});
});
});

0 comments on commit 721ecee

Please sign in to comment.