import { client, expect, faker, scenario } from "probitas";
export default scenario("User API Integration Test", {
tags: ["integration", "http", "postgres"],
})
.resource("user", () => ({
id: faker.string.uuid(),
name: faker.person.fullName(),
email: faker.internet.email(),
}))
.resource("db", () =>
client.sql.postgres.createPostgresClient({
url: {
host: "localhost",
port: 5432,
database: "app",
user: "testuser",
password: "testpassword",
},
}))
.resource("http", () =>
client.http.createHttpClient({
url: "http://localhost:8000",
}))
.setup(async (ctx) => {
const { db, user } = ctx.resources;
await db.query(
`INSERT INTO users (id, name, email) VALUES ($1, $2, $3)`,
[user.id, user.name, user.email],
);
return async () => {
await db.query(`DELETE FROM users WHERE id = $1`, [user.id]);
};
})
.step("GET /users/:id - fetch user", async (ctx) => {
const { http, user } = ctx.resources;
const res = await http.get(`/users/${user.id}`);
expect(res)
.ok()
.status(200)
.dataContains({ id: user.id, name: user.name });
})
.build();
import { client, expect, outdent, scenario } from "probitas";
export default scenario("GraphQL API Test", {
tags: ["integration", "graphql"],
})
.resource("gql", () =>
client.graphql.createGraphqlClient({
url: "http://localhost:4000/graphql",
}))
.step("echo - simple query", async (ctx) => {
const { gql } = ctx.resources;
const res = await gql.query(outdent`
query {
echo(message: "Hello GraphQL")
}
`);
expect(res)
.ok()
.dataContains({ echo: "Hello GraphQL" });
})
.step("echo - with variables", async (ctx) => {
const { gql } = ctx.resources;
const res = await gql.query(
outdent`
query Echo($msg: String!) {
echo(message: $msg)
}
`,
{ msg: "variable message" },
);
expect(res)
.ok()
.dataContains({ echo: "variable message" });
})
.step("createMessage - mutation", async (ctx) => {
const { gql } = ctx.resources;
const res = await gql.mutation(outdent`
mutation {
createMessage(text: "Hello from probitas") {
id
text
}
}
`);
expect(res).ok();
})
.build();
import { client, expect, scenario } from "probitas";
export default scenario("gRPC Service Test", {
tags: ["integration", "grpc"],
})
.resource("grpc", () =>
client.grpc.createGrpcClient({
url: "localhost:50051",
}))
.step("Echo - simple message", async (ctx) => {
const { grpc } = ctx.resources;
const res = await grpc.call("echo.v1.Echo", "Echo", {
message: "Hello from probitas",
});
expect(res)
.ok()
.dataContains({ message: "Hello from probitas" });
})
.step("EchoWithDelay - delayed response", async (ctx) => {
const { grpc } = ctx.resources;
const res = await grpc.call("echo.v1.Echo", "EchoWithDelay", {
message: "delayed",
delayMs: 100,
});
expect(res)
.ok()
.dataContains({ message: "delayed" })
.durationLessThan(5000);
})
.build();
import { client, expect, faker, scenario } from "probitas";
export default scenario("Redis Cache Test", {
tags: ["integration", "redis"],
})
.resource("redis", () =>
client.redis.createRedisClient({
url: "redis://localhost:6379",
}))
.resource("key", () => `cache:${faker.string.uuid()}`)
.setup((ctx) => {
const { redis, key } = ctx.resources;
return async () => {
await redis.del(key);
};
})
.step("SET and GET value", async (ctx) => {
const { redis, key } = ctx.resources;
await redis.set(key, "hello world");
const res = await redis.get(key);
expect(res).ok().value("hello world");
})
.step("INCR counter", async (ctx) => {
const { redis } = ctx.resources;
await redis.set("test:counter", "0");
const res = await redis.incr("test:counter");
expect(res).ok().count(1);
// Cleanup
await redis.del("test:counter");
})
.build();