Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more test cases #70

Merged
merged 13 commits into from
Sep 26, 2019
41 changes: 41 additions & 0 deletions tests/integration/doRequest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as dgraph from "../../src";

import { setSchema, setup } from "../helper";

const data = ["200", "300", "400"];

describe("doRequest", () => {
it("should insert 3Quads", async () => {
const client = await setup();
await setSchema(client, "name: string @index(fulltext) .");

const uids: string[] = [];
let res: dgraph.Response;
let req: dgraph.Request;
for (const datum of data) {
const nquad = new dgraph.NQuad();
nquad.setSubject(`_:${datum}`);
nquad.setPredicate("name");

const ov = new dgraph.Value();
prashant-shahi marked this conversation as resolved.
Show resolved Hide resolved
ov.setStrVal(`ok ${datum}`);
nquad.setObjectValue(ov);

const mu = new dgraph.Mutation();
mu.addSet(nquad);

req = new dgraph.Request();
req.setMutationsList([mu]);
req.setCommitNow(true);

res = await client.newTxn().doRequest(req);
uids.push(res.getUidsMap().get(datum));
}
const query = `{ me(func: uid(${uids.join(",")})) { name }}`;
req = new dgraph.Request();
req.setQuery(query);
res = await client.newTxn().doRequest(req);

expect(res.getJson()).toEqual({ me: [{ name: "ok 200" }, { name: "ok 300" }, { name: "ok 400" }] });
});
});
24 changes: 24 additions & 0 deletions tests/integration/upsert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ async function doUpsert(): Promise<void> {
await checkUpsertIntegrity();
}

async function doNotUpsert(): Promise<void> {
await performMutation(profiles[0]);
await performMutation(profiles[1]);
await performMutation(profiles[2]);
await checkMutationIntegrity();
const updatedProfile: Profile = {
name: "Prashant Shahi",
email: "prashantshahi@dgraph.io",
age: 24,
};
await performUpsert(updatedProfile);
await checkMutationIntegrity();
}

async function performMutation(profile: Profile): Promise<void> {
const txn = client.newTxn();
const mu = new dgraph.Mutation();
Expand Down Expand Up @@ -284,4 +298,14 @@ describe("upsert using doRequest", () => {
`);
await doUpsert();
});

it("should not perform upsert", async () => {
prashant-shahi marked this conversation as resolved.
Show resolved Hide resolved
client = await setup();
await setSchema(client, `
name: string @index(term) .
email: string @index(exact) .
age: int @index(int) .
`);
await doNotUpsert();
});
});