Skip to content

Commit cf34370

Browse files
author
asmit-patil
committed
Merge branch 'feature/global-field' into mergedFeatures
2 parents 704fe07 + ec9bc32 commit cf34370

File tree

12 files changed

+177
-54
lines changed

12 files changed

+177
-54
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
.checkpoint
55
_contents
66
_development_contents
7-
_development_contents/en-us/assets
87
unprocessible
98
_mongo_assets
109
_dev_assets

dist/util/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ exports.getOrSetRTEMarkdownAssets = (schema, entry, bucket = [], isFindNotReplac
354354
iterate(schema[i], entry, bucket, isFindNotReplace, parent);
355355
parent.pop();
356356
}
357-
else if ((schema[i].data_type === 'group' || schema[i].data_type === 'snippet') && schema[i].schema) {
357+
else if ((schema[i].data_type === 'group' || schema[i].data_type === 'global_field') && schema[i].schema) {
358358
parent.push(schema[i].uid);
359359
exports.getOrSetRTEMarkdownAssets(schema[i].schema, entry, bucket, isFindNotReplace, parent);
360360
parent.pop();

dist/util/validations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const assetPublishedStructure = (asset) => {
190190
};
191191
exports.validatePlugin = (plugin) => {
192192
if (!plugin.name || typeof plugin.name !== 'string' || plugin.name.length < 1) {
193-
throw new Error("Invalid plugin config, 'plugin.name' is a required property!");
193+
throw new Error(`Invalid plugin config, 'plugin.name' is a required property!`);
194194
}
195195
};
196196
const entryPublishedStructure = (entry) => {

jest.config.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
// For a detailed explanation regarding each configuration property, visit:
4+
// https://jestjs.io/docs/en/configuration.html
5+
6+
// All imported modules in your tests should be mocked automatically
7+
// automock: true,
8+
9+
// Stop running tests after the first failure
10+
bail: false,
11+
12+
// The directory where Jest should store its cached dependency information
13+
// cacheDirectory: './tmp/jest_rs',
14+
15+
// Automatically clear mock calls and instances between every test
16+
// clearMocks: false,
17+
18+
// Indicates whether the coverage information should be collected while executing the test
19+
collectCoverage: true,
20+
21+
// An array of glob patterns indicating a set of files for which coverage information should be collected
22+
// collectCoverageFrom: null,
23+
24+
// The directory where Jest should output its coverage files
25+
coverageDirectory: 'coverage',
26+
27+
// An array of regexp pattern strings used to skip coverage collection
28+
coveragePathIgnorePatterns: [
29+
'/node_modules/',
30+
],
31+
32+
// A list of reporter names that Jest uses when writing coverage reports
33+
coverageReporters: [
34+
'json',
35+
'html'
36+
],
37+
38+
// An object that configures minimum threshold enforcement for coverage results
39+
// coverageThreshold: null,
40+
41+
// Make calling deprecated APIs throw helpful error messages
42+
// errorOnDeprecated: false,
43+
44+
// A path to a module which exports an async function that is triggered once before all test suites
45+
// globalSetup: null,
46+
47+
// A path to a module which exports an async function that is triggered once after all test suites
48+
// globalTeardown: null,
49+
50+
// A set of global variables that need to be available in all test environments
51+
globals: {
52+
'ts-jest': {
53+
54+
}
55+
},
56+
57+
// An array of directory names to be searched recursively up from the requiring module's location
58+
// moduleDirectories: [
59+
// 'node_modules'
60+
// ],
61+
62+
// An array of file extensions your modules use
63+
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
64+
65+
// A map from regular expressions to module names that allow to stub out resources with a single module
66+
// moduleNameMapper: {
67+
// '(.*)$': '<rootDir>/src/types/$1'
68+
// },
69+
70+
// Activates notifications for test results
71+
notify: true,
72+
73+
// An enum that specifies notification mode. Requires { notify: true }
74+
notifyMode: 'always',
75+
76+
// Use this configuration option to add custom reporters to Jest
77+
// reporters: undefined,
78+
79+
reporters: [
80+
'default',
81+
['./node_modules/jest-html-reporter', {
82+
pageTitle: 'Test Report'
83+
}]
84+
],
85+
86+
// Automatically reset mock state between every test
87+
// resetMocks: false,
88+
89+
// Reset the module registry before running each individual test
90+
// resetModules: false,
91+
92+
// Automatically restore mock state between every test
93+
// restoreMocks: false,
94+
95+
// The root directory that Jest should scan for tests and modules within
96+
// rootDir: 'src',
97+
// A list of paths to directories that Jest should use to search for files in
98+
// roots: [
99+
// '<rootDir>'
100+
// ],
101+
102+
// The test environment that will be used for testing
103+
testEnvironment: 'node',
104+
105+
// Options that will be passed to the testEnvironment
106+
// testEnvironmentOptions: {},
107+
testPathIgnorePatterns: [
108+
'/test/dummy/*',
109+
// '/test/index.ts'
110+
],
111+
// The glob patterns Jest uses to detect test files
112+
testMatch: [
113+
'**/test/**/*.js?(x)',
114+
'**/test/**/*.ts?(x)',
115+
],
116+
transform: {
117+
'^.+\\.ts?$': 'ts-jest',
118+
},
119+
// testRegex: '(/test/.*|(\\.|/)(test|spec))\\.(js?|ts?)$',
120+
// The regexp pattern Jest uses to detect test files
121+
// testRegex: './test/.*.js$',
122+
123+
// Indicates whether each individual test should be reported during the run
124+
verbose: true,
125+
126+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
127+
// watchPathIgnorePatterns: [],
128+
129+
// Whether to use watchman for file crawling
130+
watchman: true
131+
}

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
{
22
"name": "@contentstack/datasync-manager",
33
"author": "Contentstack LLC <support@contentstack.com>",
4-
"version": "1.0.2",
4+
"version": "1.1.0",
55
"description": "The primary module of Contentstack DataSync. Syncs Contentstack data with your server using Contentstack Sync API",
66
"main": "dist/index.js",
77
"dependencies": {
8-
"@contentstack/datasync-asset-store-filesystem": "^1.0.0",
9-
"@contentstack/datasync-content-store-filesystem": "^1.0.1",
10-
"@contentstack/datasync-content-store-mongodb": "^1.0.1",
11-
"@contentstack/webhook-listener": "^1.0.0",
128
"debug": "4.1.1",
139
"dns-socket": "4.2.0",
1410
"lodash": "4.17.15",

src/util/build-paths.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ import { isAbsolute, join, resolve } from 'path'
1111
* @returns {Object} Returns config paths
1212
*/
1313
export const buildConfigPaths = () => {
14-
const baseDir = resolve(join(__dirname, '..', '..', '..', '..'))
15-
let pluginPath: string
16-
let tokenPath: string
14+
const baseDir = resolve(join(__dirname, '..', '..', '..', '..'))
15+
let pluginPath: string
16+
let tokenPath: string
1717

18-
if (process.env.PLUGIN_PATH) {
18+
if (process.env.PLUGIN_PATH) {
1919
if (!isAbsolute(process.env.PLUGIN_PATH)) {
2020
pluginPath = join(baseDir, process.env.PLUGIN_PATH)
2121
} else {
2222
pluginPath = process.env.PLUGIN_PATH
2323
}
2424
}
2525

26-
if (process.env.TOKEN_PATH) {
26+
if (process.env.TOKEN_PATH) {
2727
if (!isAbsolute(process.env.TOKEN_PATH)) {
2828
tokenPath = join(baseDir, process.env.TOKEN_PATH)
2929
} else {
3030
tokenPath = process.env.TOKEN_PATH
3131
}
3232
}
3333

34-
const paths: any = {
34+
const paths: any = {
3535
baseDir: resolve(join(__dirname, '..', '..')),
3636
checkpoint: resolve(join(tokenPath || join(baseDir, '..'), '.checkpoint')),
3737
failed: resolve(join(tokenPath || join(baseDir, '..'), 'unprocessible', 'failed')),
@@ -42,5 +42,5 @@ export const buildConfigPaths = () => {
4242
unprocessibleDir: resolve(join(tokenPath || baseDir, 'unprocessible')),
4343
}
4444

45-
return paths
45+
return paths
4646
}

src/util/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ export const groupItems = (items) => {
134134
* @param {Object} config - Application config
135135
*/
136136
export const formatItems = (items, config) => {
137-
//const time = new Date().toISOString()
137+
const time = new Date().toISOString()
138138
for (let i = 0, j = items.length; i < j; i++) {
139139
switch (items[i].type) {
140140
case 'asset_published':
141141
delete items[i].type
142142
items[i]._content_type_uid = formattedAssetType
143143
items[i]._type = config.contentstack.actions.publish
144144
// extra keys
145-
//items[i]._synced_at = time
145+
items[i]._synced_at = time
146146
items[i] = merge(items[i], items[i].data)
147147
items[i].locale = items[i].data.publish_details.locale
148148
break
@@ -163,7 +163,7 @@ export const formatItems = (items, config) => {
163163
items[i]._type = config.contentstack.actions.publish
164164
items[i]._content_type_uid = items[i].content_type_uid
165165
// extra keys
166-
//items[i]._synced_at = time
166+
items[i]._synced_at = time
167167
items[i] = merge(items[i], items[i].data)
168168
items[i].locale = items[i].data.publish_details.locale
169169
break
@@ -381,7 +381,7 @@ export const getOrSetRTEMarkdownAssets = (schema, entry, bucket = [], isFindNotR
381381
parent.push(schema[i].uid)
382382
iterate(schema[i], entry, bucket, isFindNotReplace, parent)
383383
parent.pop()
384-
} else if ((schema[i].data_type === 'group' || schema[i].data_type === 'snippet') && schema[i].schema) {
384+
} else if ((schema[i].data_type === 'group' || schema[i].data_type === 'global_field') && schema[i].schema) {
385385
parent.push(schema[i].uid)
386386
getOrSetRTEMarkdownAssets(schema[i].schema, entry, bucket, isFindNotReplace, parent)
387387
parent.pop()

src/util/validations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ const assetPublishedStructure = (asset) => {
209209

210210
export const validatePlugin = (plugin) => {
211211
if (!plugin.name || typeof plugin.name !== 'string' || plugin.name.length < 1) {
212-
throw new Error("Invalid plugin config, 'plugin.name' is a required property!")
212+
throw new Error(`Invalid plugin config, 'plugin.name' is a required property!`)
213213
}
214214
}
215215

test/api.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { config as internalConfig } from '../src/config'
88
import { setLogger } from '../src/util/logger'
99
import { response as emptyResponse } from './dummy/api-responses/empty'
1010
import { response as publishResponse } from './dummy/api-responses/publish'
11-
import { response as contentTypeWithGlobalFieldResponse } from './dummy/api-responses/globalfield'
1211
import { config as mockConfig } from './dummy/config'
1312

1413
const packageInfo: any = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'))
@@ -80,17 +79,6 @@ beforeEach(() => {
8079
.reply(199, {
8180
key: 'unknown reject',
8281
})
83-
84-
nock('https://api.localhost.io',{
85-
reqheaders:{
86-
'access_token':'dummyDeliveryToken',
87-
'api_key':'dummyApiKey',
88-
'x-user-agent':`datasync-manager/v${packageInfo.version}`
89-
},
90-
})
91-
.get('/v3/content_types/test?include_global_field_schema=true')
92-
.reply(200,contentTypeWithGlobalFieldResponse)
93-
9482
})
9583

9684
describe('test api - get()', () => {
@@ -147,22 +135,6 @@ describe('test api - get()', () => {
147135
})
148136
})
149137

150-
test('content-type-schema-with-global-field',()=>{
151-
const request={
152-
path:'/v3/content_types/test?include_global_field_schema=true'
153-
}
154-
let expectedGlobalFieldSchema={
155-
"data_type":"global_field",
156-
"uid":"global_field",
157-
"schema":expect.anything()
158-
}
159-
return get(request).then((response)=>{
160-
expect(response['content_type'].schema).toEqual(expect.arrayContaining([
161-
expect.objectContaining(expectedGlobalFieldSchema)
162-
]))
163-
})
164-
})
165-
166138
// test('unknown status', () => {
167139
// const request = {
168140
// path: '/unknown-status',

0 commit comments

Comments
 (0)