Skip to content

feat: added support for getLastActivities #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/contentstack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { httpClient, retryRequestHandler, retryResponseErrorHandler, retryResponseHandler } from '@contentstack/core';
import { InternalAxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
import { AxiosRequestHeaders } from 'axios';
import { handleRequest } from './cache';
import { Stack as StackClass } from './stack';
import { Policy, StackConfig } from './types';
Expand Down
34 changes: 24 additions & 10 deletions src/lib/stack.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { StackConfig, SyncStack, SyncType, LivePreviewQuery } from "./types";
import { AxiosInstance } from "@contentstack/core";
import { Asset } from "./asset";
import { AssetQuery } from "./asset-query";
import { ContentType } from "./content-type";
import { ContentTypeQuery } from "./contenttype-query";
import { synchronization } from "./synchronization";
import { TaxonomyQuery } from "./taxonomy-query";
import { GlobalFieldQuery } from "./global-field-query";
import { GlobalField } from "./global-field";
import { StackConfig, SyncStack, SyncType, LivePreviewQuery } from './types';
import { AxiosInstance, getData } from '@contentstack/core';
import { Asset } from './asset';
import { AssetQuery } from './asset-query';
import { ContentType } from './content-type';
import { ContentTypeQuery } from './contenttype-query';
import { synchronization } from './synchronization';
import {TaxonomyQuery} from './taxonomy-query';
import { GlobalFieldQuery } from './global-field-query';
import { GlobalField } from './global-field';

export class Stack {
readonly config: StackConfig;
Expand Down Expand Up @@ -188,6 +188,20 @@ export class Stack {
return this._client;
}

async getLastActivities() {
try {
const result = await getData(this._client, '/content_types', {
params: {
only_last_activity: true,
environment: this.config.environment,
},
});
return result;
} catch (error) {
throw new Error("Error fetching last activities");
}
}

/**
* @method setPort
* @memberOf Stack
Expand Down
12 changes: 12 additions & 0 deletions test/api/stack.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { stackInstance } from '../utils/stack-instance';

const stack = stackInstance();

describe('Stack methods tests', () => {
it('should check last activities', async () => {
const result = await stack.getLastActivities();
expect(result).toBeDefined();
expect(result.content_types).toBeDefined();
expect(Array.isArray(result.content_types)).toBe(true);
});
});
10 changes: 9 additions & 1 deletion test/unit/stack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Stack } from '../../src/lib/stack';
import { Asset } from '../../src/lib/asset';
import { ContentType } from '../../src/lib/content-type';
import { HOST_URL, LOCALE } from '../utils/constant';
import { syncResult } from '../utils/mocks';
import { contentTypeQueryFindResponseDataMock, syncResult } from '../utils/mocks';
import { synchronization } from '../../src/lib/synchronization';
import { ContentTypeQuery } from '../../src/lib/contenttype-query';
import { AssetQuery } from '../../src/lib/asset-query';
Expand Down Expand Up @@ -145,6 +145,14 @@ describe('Stack class tests', () => {
expect(stack.getClient().defaults.headers['preview_timestamp']).toBeUndefined();
});

it('should return last activities', async () => {
mockClient.onGet('/content_types').reply(200, contentTypeQueryFindResponseDataMock);
const response = await stack.getLastActivities();
expect(response).toEqual(contentTypeQueryFindResponseDataMock);
expect(response.content_types).toBeDefined();
expect(Array.isArray(response.content_types)).toBe(true);
});

it('should set port to 3000', () => {
stack.setPort(3000);
expect(stack.config.port).toEqual(3000);
Expand Down