feat: point field int test
This commit is contained in:
@@ -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<Post>({
|
||||
collection: slug,
|
||||
|
||||
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user