-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restore ref methods and scope release methods
- Loading branch information
1 parent
d9ae04b
commit 1ff8f72
Showing
5 changed files
with
151 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import test from 'ava' | ||
import * as mswNode from 'msw/node' | ||
|
||
import { createMockRepositoryHandler } from './__testutils__/createMockRepositoryHandler' | ||
import { createRepositoryResponse } from './__testutils__/createRepositoryResponse' | ||
import { createTestClient } from './__testutils__/createClient' | ||
import { createRef } from './__testutils__/createRef' | ||
|
||
const server = mswNode.setupServer() | ||
test.before(() => server.listen({ onUnhandledRequest: 'error' })) | ||
test.after(() => server.close()) | ||
|
||
test('returns a ref by ID', async (t) => { | ||
const ref1 = createRef(true) | ||
const ref2 = createRef(false) | ||
const response = createRepositoryResponse({ refs: [ref1, ref2] }) | ||
server.use(createMockRepositoryHandler(t, response)) | ||
|
||
const client = createTestClient(t) | ||
const res = await client.getRefById(ref2.id) | ||
|
||
t.deepEqual(res, ref2) | ||
}) | ||
|
||
test('throws if ref could not be found', async (t) => { | ||
server.use(createMockRepositoryHandler(t)) | ||
|
||
const client = createTestClient(t) | ||
|
||
await t.throwsAsync(async () => await client.getRefById('non-existant'), { | ||
message: /could not be found/i, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import test from 'ava' | ||
import * as mswNode from 'msw/node' | ||
|
||
import { createMockRepositoryHandler } from './__testutils__/createMockRepositoryHandler' | ||
import { createRepositoryResponse } from './__testutils__/createRepositoryResponse' | ||
import { createTestClient } from './__testutils__/createClient' | ||
import { createRef } from './__testutils__/createRef' | ||
|
||
const server = mswNode.setupServer() | ||
test.before(() => server.listen({ onUnhandledRequest: 'error' })) | ||
test.after(() => server.close()) | ||
|
||
test('returns a ref by label', async (t) => { | ||
const ref1 = createRef(true) | ||
const ref2 = createRef(false) | ||
const response = createRepositoryResponse({ refs: [ref1, ref2] }) | ||
server.use(createMockRepositoryHandler(t, response)) | ||
|
||
const client = createTestClient(t) | ||
const res = await client.getRefByLabel(ref2.label) | ||
|
||
t.deepEqual(res, ref2) | ||
}) | ||
|
||
test('throws if ref could not be found', async (t) => { | ||
server.use(createMockRepositoryHandler(t)) | ||
|
||
const client = createTestClient(t) | ||
|
||
await t.throwsAsync(async () => await client.getRefByLabel('non-existant'), { | ||
message: /could not be found/i, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import test from 'ava' | ||
import * as mswNode from 'msw/node' | ||
|
||
import { createMockRepositoryHandler } from './__testutils__/createMockRepositoryHandler' | ||
import { createRepositoryResponse } from './__testutils__/createRepositoryResponse' | ||
import { createTestClient } from './__testutils__/createClient' | ||
|
||
const server = mswNode.setupServer() | ||
test.before(() => server.listen({ onUnhandledRequest: 'error' })) | ||
test.after(() => server.close()) | ||
|
||
test('returns all refs', async (t) => { | ||
const response = createRepositoryResponse() | ||
server.use(createMockRepositoryHandler(t, response)) | ||
|
||
const client = createTestClient(t) | ||
const res = await client.getRefs() | ||
|
||
t.deepEqual(res, response.refs) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters