Skip to content

Fix: Fixed the failing test cases of export to csv #1922

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
May 16, 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
4 changes: 4 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
- name: Run tests for Contentstack Migration
working-directory: ./packages/contentstack-migration
run: npm run test

- name: Run tests for Contentstack Export To CSV
working-directory: ./packages/contentstack-export-to-csv
run: npm run test:unit
# - name: Fetch latest references
# run: |
# git fetch --prune
Expand Down
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: fc379207a835de8d851caa256837e2a50e0278c43e0251372f2a5292bee41fac
- filename: package-lock.json
checksum: cb3fe940f63d80f600b479a3fc0fbf25201356628acf018119d6a8ba9c53e3c7
checksum: 729b28dbdea2b41773e89095ae84c9af1f9e2a25a53640cc475c9f1a09f7f577
version: ""
426 changes: 227 additions & 199 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-to-csv",
"description": "Export entities to csv",
"version": "1.8.0",
"version": "1.8.1",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ const { configHandler } = require('@contentstack/cli-utilities');
const { runCommand } = require('@oclif/test')
const sinon = require('sinon');

const { cma } = configHandler.get('region');
const regionConfig = configHandler.get('region') || {};
const cma = regionConfig.cma || 'https://api.contentstack.io/v3';
let sandbox;

describe('Export to CSV functionality', () => {
beforeEach(() => {
if (!configHandler.get('authorisationType')) {
configHandler.set('authorisationType', 'BASIC');
configHandler.set('delete', true);
}
sandbox = sinon.createSandbox()
sandbox.stub(fs, 'createWriteStream').returns(new PassThrough())
nock(cma)
Expand All @@ -21,6 +26,10 @@ describe('Export to CSV functionality', () => {
});

afterEach(() => {
if (configHandler.get('delete')) {
configHandler.delete('delete');
configHandler.delete('authorisationType');
}
sandbox.restore();
nock.cleanAll();
});
Expand Down Expand Up @@ -204,9 +213,17 @@ describe('Export to CSV functionality', () => {

describe("Testing teams support in CLI export-to-csv", () => {
beforeEach(() => {
if (!configHandler.get('authorisationType')) {
configHandler.set('authorisationType', 'BASIC');
configHandler.set('delete', true);
}
sandbox = sinon.createSandbox();
});
afterEach(() => {
if (configHandler.get('delete')) {
configHandler.delete('delete');
configHandler.delete('authorisationType');
}
sandbox.restore();
nock.cleanAll();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
const { fancy } = require('fancy-test');
const { expect } = require('chai');
const { runCommand } = require('@oclif/test')
const inquirer = require('inquirer');
const sinon = require('sinon');
const { cliux, configHandler, managementSDKClient } = require('@contentstack/cli-utilities');
const { configHandler, managementSDKClient } = require('@contentstack/cli-utilities');
const mockData = require('../mock-data/common.mock.json');
const { getStacks, chooseBranch } = require('../../src/util/index');
const nock = require('nock');
const { cma } = configHandler.get('region');
const regionConfig = configHandler.get('region') || {};
const cma = regionConfig.cma || 'https://api.contentstack.io/v3';

describe('common utils', () => {
let managementSdk;
let sandbox
let sandbox;

beforeEach(async () => {
managementSdk = await managementSDKClient({
host: cma.replace('https://', ''),
});
sandbox = sinon.createSandbox()
sandbox = sinon.createSandbox();
});

afterEach(() => {
sandbox.restore();
nock.cleanAll();
});

describe('chooseStack', () => {
describe('choose stack from list of stacks', async () => {
beforeEach(() => {
sandbox.stub(inquirer, 'prompt').returns({
branch: mockData.stacks[0].name,
});
describe('getStacks', () => {
it('should return a list of stacks for a given organization', async () => {
sandbox.stub(inquirer, 'prompt').resolves({
stack: mockData.stacks[0].name,
});
it('Returns list of stacks', async () => {
nock(cma)
.get(`/v3/stacks?&query={"org_uid":"${mockData.organizations[0].uid}"}`)
.reply(200, { stacks: mockData.stacks });
})
await getStacks(managementSdk, mockData.organizations[0].uid);

nock(cma)
.get(`/v3/stacks?query={"org_uid":"${mockData.organizations[0].uid}"}`)
.reply(200, { stacks: mockData.stacks });

const result = await getStacks(managementSdk, mockData.organizations[0].uid);

expect(result).to.be.an('object');
});
});

Expand All @@ -49,7 +50,7 @@ describe('common utils', () => {
it('Returns list of stacks', async () => {
const { branch } = await chooseBranch([mockData.branch]);
expect(branch).to.equal(mockData.branch.uid);
})
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
determineUserOrgRole,
} = require('../../src/util/index');
const sinon = require('sinon');
const util = require('../../src/util')
const util = require('../../src/util');

describe('Test Util functions', () => {
let managementAPIClientMock;
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@contentstack/cli-cm-bulk-publish": "~1.8.0",
"@contentstack/cli-cm-clone": "~1.14.0",
"@contentstack/cli-cm-export": "~1.16.1",
"@contentstack/cli-cm-export-to-csv": "~1.8.0",
"@contentstack/cli-cm-export-to-csv": "~1.8.1",
"@contentstack/cli-cm-import": "~1.21.3",
"@contentstack/cli-cm-import-setup": "1.2.0",
"@contentstack/cli-cm-migrate-rte": "~1.5.1",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading