Merge branch 'feat/1.0' of github.com:payloadcms/payload into feat/1.0
This commit is contained in:
@@ -30,6 +30,7 @@ const collectionWithName = (collectionSlug: string): CollectionConfig => {
|
|||||||
|
|
||||||
export const slug = 'posts';
|
export const slug = 'posts';
|
||||||
export const relationSlug = 'relation';
|
export const relationSlug = 'relation';
|
||||||
|
export const pointSlug = 'point';
|
||||||
export default buildConfig({
|
export default buildConfig({
|
||||||
collections: [
|
collections: [
|
||||||
{
|
{
|
||||||
@@ -76,6 +77,16 @@ export default buildConfig({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
slug: pointSlug,
|
||||||
|
access: openAccess,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'point',
|
||||||
|
name: 'point',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
collectionWithName(relationSlug),
|
collectionWithName(relationSlug),
|
||||||
collectionWithName('dummy'),
|
collectionWithName('dummy'),
|
||||||
],
|
],
|
||||||
@@ -101,6 +112,13 @@ export default buildConfig({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await payload.create({
|
||||||
|
collection: pointSlug,
|
||||||
|
data: {
|
||||||
|
point: [10, 20],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Relation - hasMany
|
// Relation - hasMany
|
||||||
await payload.create<Post>({
|
await payload.create<Post>({
|
||||||
collection: slug,
|
collection: slug,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { initPayloadTest } from '../helpers/configHelpers';
|
import { initPayloadTest } from '../helpers/configHelpers';
|
||||||
import type { Relation } from './config';
|
import type { Relation } from './config';
|
||||||
import config, { slug, relationSlug } from './config';
|
import config, { slug, relationSlug, pointSlug } from './config';
|
||||||
import payload from '../../src';
|
import payload from '../../src';
|
||||||
import { RESTClient } from '../helpers/rest';
|
import { RESTClient } from '../helpers/rest';
|
||||||
import type { Post } from './payload-types';
|
import type { Post } from './payload-types';
|
||||||
@@ -423,6 +423,40 @@ describe('collections-rest', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('near', () => {
|
||||||
|
const point = [10, 20];
|
||||||
|
const [lat, lng] = point;
|
||||||
|
it('should return a document near a point', async () => {
|
||||||
|
const near = `${lat + 0.01}, ${lng + 0.01}, 10000`;
|
||||||
|
const { status, result } = await client.find({
|
||||||
|
slug: pointSlug,
|
||||||
|
query: {
|
||||||
|
point: {
|
||||||
|
near,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
expect(result.docs).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not return a point far away', async () => {
|
||||||
|
const near = `${lng + 1}, ${lat - 1}, 5000`;
|
||||||
|
const { status, result } = await client.find({
|
||||||
|
slug: pointSlug,
|
||||||
|
query: {
|
||||||
|
point: {
|
||||||
|
near,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
expect(result.docs).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('or', async () => {
|
it('or', async () => {
|
||||||
const post1 = await createPost({ title: 'post1' });
|
const post1 = await createPost({ title: 'post1' });
|
||||||
const post2 = await createPost({ title: 'post2' });
|
const post2 = await createPost({ title: 'post2' });
|
||||||
|
|||||||
Reference in New Issue
Block a user