-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(query): use exact match for
findOne
(#1224)
* fix(query): use exact match for `findOne` * test: add index test * test: add prefix tests * test: add more edge cases
- Loading branch information
Showing
13 changed files
with
142 additions
and
45 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
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
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
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,43 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { $fetch } from '@nuxt/test-utils' | ||
|
||
export const testContentQuery = () => { | ||
describe('content-query', () => { | ||
test('Find index', async () => { | ||
const content = await $fetch('/') | ||
|
||
// Normal Prop | ||
expect(content).includes('Index') | ||
}) | ||
|
||
test('exact match foo not found', async () => { | ||
const content = await $fetch('/features/query-content?path=/foo&findOne=1') | ||
|
||
// empty | ||
expect(content).includes('$$$$') | ||
}) | ||
|
||
test('exact match foo/bar found', async () => { | ||
const content = await $fetch('/features/query-content?path=/foo/bar&findOne=1') | ||
|
||
// empty | ||
expect(content).includes('prefix:foo:bar.md$$') | ||
}) | ||
|
||
test('prefix queries', async () => { | ||
const content = await $fetch('/features/query-content?path=/foo') | ||
|
||
expect(content).includes('prefix:foo:bar.md') | ||
expect(content).includes('prefix:foo:baz.md') | ||
expect(content).includes('prefix:foobarbaz.md') | ||
}) | ||
|
||
test('directory listing', async () => { | ||
const content = await $fetch('/features/query-content?path=/foo/') | ||
|
||
expect(content).includes('prefix:foo:bar.md') | ||
expect(content).includes('prefix:foo:baz.md') | ||
expect(content).not.includes('prefix:foobarbaz.md') | ||
}) | ||
}) | ||
} |
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
File renamed without changes.
Empty file.
Empty file.
Empty file.
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 @@ | ||
<template> | ||
<div> | ||
<pre>$${{ data }}$$</pre> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
const route = useRoute() | ||
const path = route.query.path | ||
const findOne = route.query.findOne | ||
const { data } = await useAsyncData('foo', () => { | ||
const q = queryContent('/_partial/prefix' + path) | ||
return findOne ? q.findOne() : q.find() | ||
}, { | ||
transform: (data) => { | ||
return findOne ? data._id : data.map(d => d._id) | ||
} | ||
}) | ||
</script> |