Skip to content

Commit

Permalink
test: updated unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Mar 7, 2024
1 parent 0d4e502 commit 75f4070
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
27 changes: 0 additions & 27 deletions test/unit/contenttype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,3 @@ describe('ContentType class', () => {
expect(response).toEqual(contentTypeResponseMock.content_type);
});
});

describe('ContentType Query class', () => {
let contentType: ContentType;
let client: AxiosInstance;
let mockClient: MockAdapter;

beforeAll(() => {
client = httpClient(MOCK_CLIENT_OPTIONS);
mockClient = new MockAdapter(client as any);
});

beforeEach(() => {
contentType = new ContentType(client, 'contentTypeUid');
});
it('should get entries which matches the fieldUid and values', () => {
const query = contentType.Query().containedIn('fieldUID', ['value']);
expect(query._parameters).toStrictEqual({'fieldUID': {'$in': ['value']}});
});
it('should get entries which does not match the fieldUid and values', () => {
const query = contentType.Query().notContainedIn('fieldUID', ['value', 'value2']);
expect(query._parameters).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}});
});
it('should get entries which does not match the fieldUid - notExists', () => {
const query = contentType.Query().notExists('fieldUID');
expect(query._parameters).toStrictEqual({'fieldUID': {'$exists': false}});
});
});
32 changes: 32 additions & 0 deletions test/unit/entry-queryable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { AxiosInstance, httpClient } from '@contentstack/core';
import { ContentType } from '../../src/lib/content-type';
import MockAdapter from 'axios-mock-adapter';
import { MOCK_CLIENT_OPTIONS } from '../utils/constant';


describe('Query Operators API test cases', () => {
let contentType: ContentType;
let client: AxiosInstance;
let mockClient: MockAdapter;

beforeAll(() => {
client = httpClient(MOCK_CLIENT_OPTIONS);
mockClient = new MockAdapter(client as any);
});

beforeEach(() => {
contentType = new ContentType(client, 'contentTypeUid');
});
it('should get entries which matches the fieldUid and values', () => {
const query = contentType.Entry().query().containedIn('fieldUID', ['value']);
expect(query._parameters).toStrictEqual({'fieldUID': {'$in': ['value']}});
});
it('should get entries which does not match the fieldUid and values', () => {
const query = contentType.Entry().query().notContainedIn('fieldUID', ['value', 'value2']);
expect(query._parameters).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}});
});
it('should get entries which does not match the fieldUid - notExists', () => {
const query = contentType.Entry().query().notExists('fieldUID');
expect(query._parameters).toStrictEqual({'fieldUID': {'$exists': false}});
});
});

0 comments on commit 75f4070

Please sign in to comment.