Skip to content

Commit e82ed3f

Browse files
committed
Convert to vitest functions and syntax
1 parent 5421e16 commit e82ed3f

4 files changed

Lines changed: 38 additions & 34 deletions

File tree

src/full-promises.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ClientSecurity } from "./util";
22
import * as v1 from "./v1";
33
import { Consistency } from "./v1";
44
import { generateTestToken } from './__utils__/helpers'
5+
import { describe, it, expect } from 'vitest'
56

67
describe("a check following a write of schema and relationships", () => {
78
it("should succeed", async () => {

src/full.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { ClientSecurity } from "./util";
22
import * as v1 from "./v1";
33
import { Consistency } from "./v1";
44
import { generateTestToken } from './__utils__/helpers'
5+
import { describe, it, expect } from 'vitest'
56

67
describe("a check following a write of schema and relationships", () => {
7-
it("should succeed", (done) => {
8+
it("should succeed", () => new Promise<void>((done) => {
89
// Write the schema.
910
const token = generateTestToken('full-test')
1011
const v1client = v1.NewClient(token, "localhost:50051", ClientSecurity.INSECURE_LOCALHOST_ALLOWED);
@@ -80,5 +81,5 @@ describe("a check following a write of schema and relationships", () => {
8081
});
8182
});
8283
});
83-
});
84+
}));
8485
});

src/v1-promise.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
WriteRelationshipsRequest,
2121
WriteSchemaRequest,
2222
} from './v1';
23+
import { describe, it, expect, beforeEach } from 'vitest'
2324

2425
describe('a check with an unknown namespace', () => {
2526
it('should raise a failed precondition', async () => {
@@ -412,7 +413,7 @@ describe('Lookup APIs', () => {
412413
);
413414

414415
const result = await client.lookupSubjects(lookupSubjectRequest);
415-
expect(['someuser', 'someuser2']).toContain(result[0].subjectObjectId);
416+
expect(['someuser', 'someuser2']).toContain(result[0].subject?.subjectObjectId);
416417
client.close();
417418
});
418419

@@ -441,7 +442,7 @@ describe('Lookup APIs', () => {
441442
new grpc.Metadata(),
442443
{} as grpc.CallOptions
443444
);
444-
expect(['someuser', 'someuser2']).toContain(result[0].subjectObjectId);
445+
expect(['someuser', 'someuser2']).toContain(result[0].subject?.subjectObjectId);
445446

446447
const resStream = await client.lookupResources(
447448
lookupResourceRequest,
@@ -479,7 +480,7 @@ describe('Experimental Service', () => {
479480
client.close();
480481
});
481482

482-
it('can bulk import relationships', (done) => {
483+
it('can bulk import relationships', () => new Promise<void>((done, fail) => {
483484
const { promises: client } = NewClient(
484485
token,
485486
'localhost:50051',
@@ -488,7 +489,7 @@ describe('Experimental Service', () => {
488489

489490
const writeStream = client.bulkImportRelationships((err, value) => {
490491
if (err) {
491-
done.fail(err);
492+
fail(err);
492493
}
493494

494495
expect(value?.numLoaded).toEqual('2');
@@ -497,7 +498,7 @@ describe('Experimental Service', () => {
497498
});
498499

499500
writeStream.on('error', (e) => {
500-
done.fail(e);
501+
fail(e);
501502
});
502503

503504
const resource = ObjectReference.create({
@@ -532,7 +533,7 @@ describe('Experimental Service', () => {
532533
);
533534

534535
writeStream.end();
535-
});
536+
}));
536537

537538
it('can bulk export relationships', async () => {
538539
const { promises: client } = NewClient(

src/v1.test.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import {
2626
WriteRelationshipsResponse,
2727
WriteSchemaRequest,
2828
} from "./v1";
29+
import { describe, it, expect, beforeEach } from 'vitest'
2930

3031
describe("a check with an unknown namespace", () => {
31-
it("should raise a failed precondition", (done) => {
32+
it("should raise a failed precondition", () => new Promise<void>((done) => {
3233
const resource = ObjectReference.create({
3334
objectType: "test/somenamespace",
3435
objectId: "bar",
@@ -58,11 +59,11 @@ describe("a check with an unknown namespace", () => {
5859
client.close();
5960
done();
6061
});
61-
});
62+
}));
6263
});
6364

6465
describe("a check with an known namespace", () => {
65-
it("should succeed", (done) => {
66+
it("should succeed", () => new Promise<void>((done) => {
6667
// Write some schema.
6768
const client = NewClient(
6869
generateTestToken("v1-namespace"),
@@ -165,10 +166,10 @@ describe("a check with an known namespace", () => {
165166
client.close();
166167
done();
167168
});
168-
});
169+
}));
169170

170171
describe("with caveated relations", () => {
171-
it("should succeed", (done) => {
172+
it("should succeed", () => new Promise<void>((done) => {
172173
// Write some schema.
173174
const client = NewClient(
174175
generateTestToken("v1-namespace-caveats"),
@@ -279,14 +280,14 @@ describe("a check with an known namespace", () => {
279280
client.close();
280281
done();
281282
});
282-
});
283+
}));
283284
});
284285
});
285286

286287
describe("Lookup APIs", () => {
287288
let token: string;
288289

289-
beforeEach((done) => {
290+
beforeEach(() => new Promise<void>((done) => {
290291
token = generateTestToken("v1-lookup");
291292
const client = NewClient(
292293
token,
@@ -348,9 +349,9 @@ describe("Lookup APIs", () => {
348349
done();
349350
});
350351
});
351-
});
352+
}));
352353

353-
it("can lookup subjects", (done) => {
354+
it("can lookup subjects", () => new Promise<void>((done, fail) => {
354355
const client = NewClient(
355356
token,
356357
"localhost:50051",
@@ -375,7 +376,7 @@ describe("Lookup APIs", () => {
375376
const resStream = client.lookupSubjects(request);
376377

377378
resStream.on("data", function (subject: LookupSubjectsResponse) {
378-
expect(["someuser", "someuser2"]).toContain(subject.subjectObjectId);
379+
expect(["someuser", "someuser2"]).toContain(subject.subject?.subjectObjectId);
379380
});
380381

381382
resStream.on("end", function () {
@@ -385,15 +386,15 @@ describe("Lookup APIs", () => {
385386

386387
resStream.on("error", function (e) {
387388
client.close();
388-
done.fail(e);
389+
fail(e);
389390
});
390391

391392
resStream.on("status", function (status) {
392393
expect(status.code).toEqual(grpc.status.OK);
393394
});
394-
});
395+
}));
395396

396-
it("can lookup resources", (done) => {
397+
it("can lookup resources", () => new Promise<void>((done, fail) => {
397398
const client = NewClient(
398399
token,
399400
"localhost:50051",
@@ -430,17 +431,17 @@ describe("Lookup APIs", () => {
430431

431432
resStream.on("error", function (e) {
432433
client.close();
433-
done.fail(e);
434+
fail(e);
434435
});
435436

436437
resStream.on("status", function (status) {
437438
expect(status.code).toEqual(grpc.status.OK);
438439
});
439-
});
440+
}));
440441
});
441442

442443
describe("a check with a negative timeout", () => {
443-
it("should fail immediately", (done) => {
444+
it("should fail immediately", () => new Promise<void>((done) => {
444445
const resource = ObjectReference.create({
445446
objectType: "test/somenamespace",
446447
objectId: "bar",
@@ -474,13 +475,13 @@ describe("a check with a negative timeout", () => {
474475
client.close();
475476
done();
476477
});
477-
});
478+
}));
478479
});
479480

480481
describe("Experimental Service", () => {
481482
let token: string;
482483

483-
beforeEach((done) => {
484+
beforeEach(() => new Promise<void>((done) => {
484485
token = generateTestToken("v1-experimental-service");
485486
const client = NewClient(
486487
token,
@@ -503,9 +504,9 @@ describe("Experimental Service", () => {
503504
client.close();
504505
done();
505506
});
506-
});
507+
}));
507508

508-
it("can bulk import relationships", (done) => {
509+
it("can bulk import relationships", () => new Promise<void>((done, fail) => {
509510
const client = NewClient(
510511
token,
511512
"localhost:50051",
@@ -514,7 +515,7 @@ describe("Experimental Service", () => {
514515

515516
const writeStream = client.bulkImportRelationships((err, value) => {
516517
if (err) {
517-
done.fail(err);
518+
fail(err);
518519
}
519520

520521
expect(value?.numLoaded).toEqual("2");
@@ -523,7 +524,7 @@ describe("Experimental Service", () => {
523524
});
524525

525526
writeStream.on("error", (e) => {
526-
done.fail(e);
527+
fail(e);
527528
});
528529

529530
const resource = ObjectReference.create({
@@ -559,9 +560,9 @@ describe("Experimental Service", () => {
559560
);
560561

561562
writeStream.end();
562-
});
563+
}));
563564

564-
it("can bulk export relationships", (done) => {
565+
it("can bulk export relationships", () => new Promise<void>((done, fail) => {
565566
const client = NewClient(
566567
token,
567568
"localhost:50051",
@@ -655,12 +656,12 @@ describe("Experimental Service", () => {
655656

656657
resStream.on("error", function (e) {
657658
client.close();
658-
done.fail(e);
659+
fail(e);
659660
});
660661

661662
resStream.on("status", function (status) {
662663
expect(status.code).toEqual(grpc.status.OK);
663664
});
664665
});
665-
});
666+
}));
666667
});

0 commit comments

Comments
 (0)