Skip to content

Commit 2dce7e4

Browse files
committed
test: changes based on PR feedback [CS-36688]
1 parent df5b370 commit 2dce7e4

File tree

5 files changed

+79
-52
lines changed

5 files changed

+79
-52
lines changed

lib/stack/branch/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function Branch (http, data = {}) {
5757
* import * as contentstack from '@contentstack/management'
5858
* const client = contentstack.client()
5959
*
60-
* client.stack({ api_key: 'api_key'}).branch('branch_uid').compare()
60+
* client.stack({ api_key: 'api_key'}).branch('branch_uid').compare('compare_uid')
6161
*
6262
*/
6363
this.compare = (compareBranchUid) => {
@@ -113,21 +113,25 @@ export function Branch (http, data = {}) {
113113
* @example
114114
* import * as contentstack from '@contentstack/management'
115115
* const client = contentstack.client()
116-
*
117-
* client.stack({ api_key: 'api_key'}).branch().merge({
116+
*
117+
* const params = {
118118
* base_branch: "main",
119119
* compare_branch: "dev",
120120
* default_merge_strategy: "merge_prefer_base",
121+
* merge_comment: "Merging dev into main",
122+
* no_revert: true,
123+
* }
124+
* const mergeObj = {
121125
* item_merge_strategies: [
122126
* {
123127
* uid: "global_field_uid",
124128
* type: "global_field",
125129
* merge_strategy: "merge_prefer_base"
126130
* }
127131
* ],
128-
* merge_comment: "Merging dev into main",
129-
* no_revert: true
130-
* })
132+
* }
133+
*
134+
* client.stack({ api_key: 'api_key'}).branch().merge(mergeObj, params)
131135
*/
132136
this.merge = async (mergeObj, params) => {
133137
const url = '/merge';

test/unit/mock/objects.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -588,69 +588,69 @@ const installationMock = {
588588
}
589589

590590
const globalFieldDiff = [{
591-
"uid": "global_field_uid",
592-
"title": "Global Field Title",
593-
"type": "global_field",
594-
"status": "base_only"
591+
uid: 'global_field_uid',
592+
title: 'Global Field Title',
593+
type: 'global_field',
594+
status: 'base_only'
595595
}]
596596

597597
const contentTypeDiff = [{
598-
"uid": "content_type_uid_1",
599-
"title": "Content Type 1 Title",
600-
"type": "content_type",
601-
"status": "compare_only"
598+
uid: 'content_type_uid_1',
599+
title: 'Content Type 1 Title',
600+
type: 'content_type',
601+
status: 'compare_only'
602602
},
603603
{
604-
"uid": "content_type_uid_2",
605-
"title": "Content Type 2 Title",
606-
"type": "content_type",
607-
"status": "modified"
604+
uid: 'content_type_uid_2',
605+
title: 'Content Type 2 Title',
606+
type: 'content_type',
607+
status: 'modified'
608608
}]
609609

610610
const branchCompareAllMock = {
611-
"branches": {
612-
"base_branch": "UID",
613-
"compare_branch": "dev"
611+
branches: {
612+
base_branch: 'UID',
613+
compare_branch: 'dev'
614614
},
615-
"diff": [...globalFieldDiff, ...contentTypeDiff],
616-
"next_url":"https://api.contentstack.io/v3/stacks/branches/compare?base_branch=main&compare_branch=dev&skip=0&limit=100"
615+
diff: [...globalFieldDiff, ...contentTypeDiff],
616+
next_url:'https://api.contentstack.io/v3/stacks/branches/compare?base_branch=main&compare_branch=dev&skip=0&limit=100'
617617
}
618618

619619
const branchCompareContentTypeMock = {
620-
"branches": {
621-
"base_branch": "UID",
622-
"compare_branch": "dev"
620+
branches: {
621+
base_branch: 'UID',
622+
compare_branch: 'dev'
623623
},
624-
"diff": [ ...contentTypeDiff ],
625-
"next_url":"https://api.contentstack.io/v3/stacks/branches/compare?base_branch=main&compare_branch=dev&skip=0&limit=100"
624+
diff: [ ...contentTypeDiff ],
625+
next_url:'https://api.contentstack.io/v3/stacks/branches/compare?base_branch=main&compare_branch=dev&skip=0&limit=100'
626626
}
627627

628628
const branchCompareGlobalFieldMock = {
629-
"branches": {
630-
"base_branch": "UID",
631-
"compare_branch": "dev"
629+
branches: {
630+
base_branch: 'UID',
631+
compare_branch: 'dev'
632632
},
633-
"diff": [...globalFieldDiff],
634-
"next_url":"https://api.contentstack.io/v3/stacks/branches/compare?base_branch=main&compare_branch=dev&skip=0&limit=100"
633+
diff: [...globalFieldDiff],
634+
next_url:'https://api.contentstack.io/v3/stacks/branches/compare?base_branch=main&compare_branch=dev&skip=0&limit=100'
635635
}
636636

637637
const branchMergeAllMock = {
638-
"uid": "UID",
639-
"stack": "stack_uid",
640-
"created_at": "created_at_date",
641-
"updated_at": "updated_at_date",
642-
"created_by": "created_by_user_uid",
643-
"updated_by": "updated_by_user_uid",
644-
"merge_details": {
645-
"base_branch": "main",
646-
"compare_branch": "dev",
647-
"status": "in_progress"
638+
uid: 'UID',
639+
stack: 'stack_uid',
640+
created_at: 'created_at_date',
641+
updated_at: 'updated_at_date',
642+
created_by: 'created_by_user_uid',
643+
updated_by: 'updated_by_user_uid',
644+
merge_details: {
645+
base_branch: 'main',
646+
compare_branch: 'dev',
647+
status: 'in_progress'
648648
},
649-
"merged_at": null,
650-
"errors": [
649+
merged_at: null,
650+
errors: [
651651
{
652-
"code": "error_code",
653-
"message": "Error message"
652+
code: 'error_code',
653+
message: 'Error message'
654654
}
655655
]
656656
}
@@ -660,7 +660,7 @@ const branchMergeQueueFetchMock = {
660660
}
661661

662662
const branchMergeQueueFindMock = {
663-
"queue": [
663+
queue: [
664664
{ ...branchMergeQueueFetchMock }
665665
]
666666
}

types/stack/branch/compare.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { Response } from '../../contentstackCollection';
21
import { AnyProperty } from '../../utility/fields';
32
import { Pagination } from '../../utility/pagination';
43

54
export interface Compare {
65
all(params: Pagination & AnyProperty): Promise<AnyProperty>
7-
contentTypes(params: Params) : Promise<Response>
8-
globalFields(params: Params) : Promise<Response>
6+
contentTypes(params: Params) : Promise<AnyProperty>
7+
globalFields(params: Params) : Promise<AnyProperty>
98
}
109

1110
export type Params = {

types/stack/branch/index.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { AnyProperty, SystemFields } from "../../utility/fields";
22
import { Queryable, SystemFunction } from "../../utility/operations";
3+
import { Compare } from "./compare";
4+
import { MergeQueue, MergeQueues } from "./merge-queue";
35

46
export interface Branch extends SystemFields, SystemFunction<Branch> {
7+
compare(compareBranchUid: string): Compare
8+
mergeQueue(mergeJobUid?: string): MergeQueue | MergeQueues
9+
merge(mergeObj: IMergeObj, params: IMergeParams)
510
}
611

712
export interface Branches extends Queryable<Branch, {branch: BranchData}> {
@@ -10,4 +15,24 @@ export interface Branches extends Queryable<Branch, {branch: BranchData}> {
1015
export interface BranchData extends AnyProperty {
1116
uid: string
1217
source: string
18+
}
19+
20+
export interface IMergeObj {
21+
item_merge_strategies?: IMergeStrategy[]
22+
}
23+
24+
export interface IMergeStrategy {
25+
uid: string
26+
type: string
27+
merge_strategy: MergeStrategy
28+
}
29+
30+
export type MergeStrategy = "merge_prefer_base" | "merge_prefer_compare" | "overwrite_with_compare" | "merge_new_only" | "merge_modified_only_prefer_base" | "merge_modified_only_prefer_compare" | "ignore"
31+
32+
export interface IMergeParams {
33+
base_branch: string
34+
compare_branch: string
35+
default_merge_strategy: MergeStrategy
36+
merge_comment: string
37+
no_revert?: boolean
1338
}

types/stack/branch/merge-queue.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Response } from "../../contentstackCollection"
21
import { AnyProperty } from "../../utility/fields"
32

43
export interface MergeQueue {

0 commit comments

Comments
 (0)