Skip to content

Commit

Permalink
chore(tests): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
destifo committed May 24, 2024
1 parent b0fe14e commit f30e190
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 487 deletions.
39 changes: 0 additions & 39 deletions typegate/tests/runtimes/deno/deno_dir.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import os
import sys

from typegraph.gen.exports.core import (
ArtifactResolutionConfig,
MigrationAction,
MigrationConfig,
)
from typegraph.graph.shared_types import BasicAuth
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
from typegraph.graph.typegraph import Graph
from typegraph.policy import Policy
from typegraph.runtimes.deno import DenoRuntime
Expand All @@ -30,32 +20,3 @@ def deno_dir(g: Graph):
name="doAddition",
),
)


cwd = sys.argv[1]
PORT = sys.argv[2]
gate = f"http://localhost:{PORT}"
auth = BasicAuth("admin", "password")

deno_tg = deno_dir()
deploy_result = tg_deploy(
deno_tg,
TypegraphDeployParams(
base_url=gate,
auth=auth,
typegraph_path=os.path.join(cwd, "deno_dir.py"),
artifacts_config=ArtifactResolutionConfig(
dir=cwd,
prefix=None,
disable_artifact_resolution=None,
codegen=None,
prisma_migration=MigrationConfig(
migration_dir="prisma-migrations",
global_action=MigrationAction(reset=False, create=True),
runtime_actions=None,
),
),
),
)

print(deploy_result.serialized)
35 changes: 18 additions & 17 deletions typegate/tests/runtimes/deno/deno_dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

export const denoDirs = await typegraph({
name: "deno_dirs",
}, (g) => {
const deno = new DenoRuntime();
const pub = Policy.public();
export const tg = await typegraph(
{
name: "deno_dirs",
},
(g) => {
const deno = new DenoRuntime();
const pub = Policy.public();

g.expose({
testDir: deno.import(
t.struct({ a: t.float(), b: t.float() }),
t.float(),
{
module: "ts/dep/main.ts",
name: "doAddition",
deps: ["ts/dep/nested"],
},
).withPolicy(pub),
});
});
g.expose({
testDir: deno
.import(t.struct({ a: t.float(), b: t.float() }), t.float(), {
module: "ts/dep/main.ts",
name: "doAddition",
deps: ["ts/dep/nested"],
})
.withPolicy(pub),
});
},
);
78 changes: 4 additions & 74 deletions typegate/tests/runtimes/deno/deno_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,8 @@
// SPDX-License-Identifier: Elastic-2.0

import { gql, Meta } from "../../utils/mod.ts";
import * as path from "std/path/mod.ts";
import { testDir } from "test-utils/dir.ts";
import { BasicAuth, tgDeploy } from "@typegraph/sdk/tg_deploy.js";
import { denoDirs } from "./deno_dir.ts";
import { generateSyncConfig } from "../../utils/s3.ts";

const cwd = path.join(testDir, "runtimes/deno");
const auth = new BasicAuth("admin", "password");

const localSerializedMemo = denoDirs.serialize({
prismaMigration: {
globalAction: {
create: true,
reset: false,
},
migrationDir: "prisma-migrations",
},
dir: cwd,
});
const reusableTgOutput = {
...denoDirs,
serialize: (_: any) => localSerializedMemo,
};

const { syncConfig, cleanUp } = generateSyncConfig("deno-dirs-sync-test");

Meta.test(
Expand All @@ -36,9 +14,8 @@ Meta.test(
await t.should(
"work for deps specified with dir on Python SDK",
async () => {
const engine = await t.engineFromTgDeployPython(
const engine = await t.engine(
"runtimes/deno/deno_dir.py",
cwd,
);

await gql`
Expand All @@ -53,33 +30,10 @@ Meta.test(
},
);

const port = t.port;
const gate = `http://localhost:${port}`;

await t.should(
"work for deps specified with dir on TypeScript SDK",
async () => {
const { serialized, typegate: _gateResponseAdd } = await tgDeploy(
reusableTgOutput,
{
baseUrl: gate,
auth,
artifactsConfig: {
prismaMigration: {
globalAction: {
create: true,
reset: false,
},
migrationDir: "prisma-migrations",
},
dir: cwd,
},
typegraphPath: path.join(cwd, "deno_dirs.ts"),
secrets: {},
},
);

const engine = await t.engineFromDeployed(serialized);
const engine = await t.engine("runtimes/deno/deno_dir.ts");

await gql`
query {
Expand Down Expand Up @@ -110,9 +64,8 @@ Meta.test(
await t.should(
"work for deps specified with dir on Python SDK",
async () => {
const engine = await t.engineFromTgDeployPython(
const engine = await t.engine(
"runtimes/deno/deno_dir.py",
cwd,
);

await gql`
Expand All @@ -127,33 +80,10 @@ Meta.test(
},
);

const port = t.port;
const gate = `http://localhost:${port}`;

await t.should(
"work for deps specified with dir on TypeScript SDK",
async () => {
const { serialized, typegate: _gateResponseAdd } = await tgDeploy(
reusableTgOutput,
{
baseUrl: gate,
auth,
artifactsConfig: {
prismaMigration: {
globalAction: {
create: true,
reset: false,
},
migrationDir: "prisma-migrations",
},
dir: cwd,
},
typegraphPath: path.join(cwd, "deno_dirs.ts"),
secrets: {},
},
);

const engine = await t.engineFromDeployed(serialized);
const engine = await t.engine("runtimes/deno/deno_dir.ts");

await gql`
query {
Expand Down
76 changes: 4 additions & 72 deletions typegate/tests/runtimes/deno/deno_glob_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,8 @@
// SPDX-License-Identifier: Elastic-2.0

import { gql, Meta } from "../../utils/mod.ts";
import * as path from "std/path/mod.ts";
import { testDir } from "test-utils/dir.ts";
import { BasicAuth, tgDeploy } from "@typegraph/sdk/tg_deploy.js";
import { denoGlobs } from "./deno_globs.ts";
import { generateSyncConfig } from "../../utils/s3.ts";

const cwd = path.join(testDir, "runtimes/deno");
const auth = new BasicAuth("admin", "password");

const localSerializedMemo = denoGlobs.serialize({
prismaMigration: {
globalAction: {
create: true,
reset: false,
},
migrationDir: "prisma-migrations",
},
dir: cwd,
});
const reusableTgOutput = {
...denoGlobs,
serialize: (_: any) => localSerializedMemo,
};

const { syncConfig, cleanUp } = generateSyncConfig("deno-globs-sync-test");

Meta.test(
Expand All @@ -36,9 +14,8 @@ Meta.test(
await t.should(
"work for deps specified with glob on Python SDK",
async () => {
const engine = await t.engineFromTgDeployPython(
const engine = await t.engine(
"runtimes/deno/deno_globs.py",
cwd,
);

await gql`
Expand All @@ -53,32 +30,10 @@ Meta.test(
},
);

const port = t.port;
const gate = `http://localhost:${port}`;
await t.should(
"work for deps specified with glob on TypeScript SDK",
async () => {
const { serialized, typegate: _gateResponseAdd } = await tgDeploy(
reusableTgOutput,
{
baseUrl: gate,
auth,
artifactsConfig: {
prismaMigration: {
globalAction: {
create: true,
reset: false,
},
migrationDir: "prisma-migrations",
},
dir: cwd,
},
typegraphPath: path.join(cwd, "deno_globs.ts"),
secrets: {},
},
);

const engine = await t.engineFromDeployed(serialized);
const engine = await t.engine("runtimes/deno/deno_globs.ts");

await gql`
query {
Expand Down Expand Up @@ -109,9 +64,8 @@ Meta.test(
await t.should(
"work for deps specified with glob on Python SDK",
async () => {
const engine = await t.engineFromTgDeployPython(
const engine = await t.engine(
"runtimes/deno/deno_globs.py",
cwd,
);

await gql`
Expand All @@ -126,32 +80,10 @@ Meta.test(
},
);

const port = t.port;
const gate = `http://localhost:${port}`;
await t.should(
"work for deps specified with glob on TypeScript SDK",
async () => {
const { serialized, typegate: _gateResponseAdd } = await tgDeploy(
reusableTgOutput,
{
baseUrl: gate,
auth,
artifactsConfig: {
prismaMigration: {
globalAction: {
create: true,
reset: false,
},
migrationDir: "prisma-migrations",
},
dir: cwd,
},
typegraphPath: path.join(cwd, "deno_globs.ts"),
secrets: {},
},
);

const engine = await t.engineFromDeployed(serialized);
const engine = await t.engine("runtimes/deno/deno_globs.ts");

await gql`
query {
Expand Down
39 changes: 0 additions & 39 deletions typegate/tests/runtimes/deno/deno_globs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import os
import sys

from typegraph.gen.exports.core import (
ArtifactResolutionConfig,
MigrationAction,
MigrationConfig,
)
from typegraph.graph.shared_types import BasicAuth
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
from typegraph.graph.typegraph import Graph
from typegraph.policy import Policy
from typegraph.runtimes.deno import DenoRuntime
Expand All @@ -30,32 +20,3 @@ def deno_globs(g: Graph):
name="doAddition",
),
)


cwd = sys.argv[1]
PORT = sys.argv[2]
gate = f"http://localhost:{PORT}"
auth = BasicAuth("admin", "password")

deno_tg = deno_globs()
deploy_result = tg_deploy(
deno_tg,
TypegraphDeployParams(
base_url=gate,
auth=auth,
typegraph_path=os.path.join(cwd, "deno_globs.py"),
artifacts_config=ArtifactResolutionConfig(
dir=cwd,
prefix=None,
disable_artifact_resolution=None,
codegen=None,
prisma_migration=MigrationConfig(
migration_dir="prisma-migrations",
global_action=MigrationAction(reset=False, create=True),
runtime_actions=None,
),
),
),
)

print(deploy_result.serialized)
2 changes: 1 addition & 1 deletion typegate/tests/runtimes/deno/deno_globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

export const denoGlobs = await typegraph(
export const tg = await typegraph(
{
name: "deno_globs",
},
Expand Down
Loading

0 comments on commit f30e190

Please sign in to comment.