diff --git a/test/collections-rest/config.ts b/test/collections-rest/config.ts index 1b40d11d3..0f8f212c2 100644 --- a/test/collections-rest/config.ts +++ b/test/collections-rest/config.ts @@ -30,6 +30,7 @@ const collectionWithName = (collectionSlug: string): CollectionConfig => { export const slug = 'posts'; export const relationSlug = 'relation'; +export const pointSlug = 'point'; export default buildConfig({ collections: [ { @@ -76,6 +77,16 @@ export default buildConfig({ }, ], }, + { + slug: pointSlug, + access: openAccess, + fields: [ + { + type: 'point', + name: 'point', + }, + ], + }, collectionWithName(relationSlug), collectionWithName('dummy'), ], @@ -101,6 +112,13 @@ export default buildConfig({ }, }); + await payload.create({ + collection: pointSlug, + data: { + point: [10, 20], + }, + }); + // Relation - hasMany await payload.create({ collection: slug, diff --git a/test/collections-rest/int.spec.ts b/test/collections-rest/int.spec.ts index 68a222a78..0da6d1c9f 100644 --- a/test/collections-rest/int.spec.ts +++ b/test/collections-rest/int.spec.ts @@ -1,7 +1,7 @@ import mongoose from 'mongoose'; import { initPayloadTest } from '../helpers/configHelpers'; import type { Relation } from './config'; -import config, { slug, relationSlug } from './config'; +import config, { slug, relationSlug, pointSlug } from './config'; import payload from '../../src'; import { RESTClient } from '../helpers/rest'; 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 () => { const post1 = await createPost({ title: 'post1' }); const post2 = await createPost({ title: 'post2' });