-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstack_test.dart
More file actions
174 lines (152 loc) · 5.94 KB
/
stack_test.dart
File metadata and controls
174 lines (152 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import 'package:contentstack/contentstack.dart';
import 'package:contentstack/contentstack.dart' as contentstack;
import 'package:contentstack/src/query_params.dart';
import 'package:dotenv/dotenv.dart';
import 'package:logger/logger.dart';
import 'package:test/test.dart';
void main() {
final logger = Logger(printer: PrettyPrinter());
final env = DotEnv(includePlatformEnvironment: true)..load();
final apiKey = env['apiKey']!;
final host = env['host'];
final deliveryToken = env['deliveryToken']!;
final environment = env['environment']!;
final branch = 'development';
logger.i('credentials loaded..');
final Stack stack =
Stack(apiKey, deliveryToken, environment, host: host, branch: branch);
group('functional testcases for stack', () {
test('check stack credentials', () {
expect(stack.apiKey, apiKey);
expect(stack.deliveryToken, deliveryToken);
expect(stack.environment, environment);
expect(stack.host, host);
expect(stack.branch, branch);
});
test('Stack initialization with Host', () {
final stack = contentstack.Stack('apiKey', 'accessToken', 'environment',
host: 'com.contentstack.com');
expect(stack.host, equals('com.contentstack.com'));
});
test('Stack initialization with EU Region', () {
final stack = contentstack.Stack('apiKey', 'accessToken', 'environment',
region: contentstack.Region.eu);
expect(stack.region, equals(contentstack.Region.eu));
expect(stack.host, equals('eu-cdn.contentstack.com'));
});
test('Stack initialization with EU Region and Host', () {
final stack = contentstack.Stack('apiKey', 'accessToken', 'environment',
region: contentstack.Region.eu, host: 'com.contentstack.com');
expect(stack.host, equals('eu-com.contentstack.com'));
});
test('Stack initialization without API Key', () {
try {
final stack = contentstack.Stack(' !', 'accessToken', 'environment');
expect(stack, equals(null));
} catch (e) {
print('Error from Stack initialization without API Key : $e');
}
});
test('stack initialization without Delivery Token', () {
try {
final stack = contentstack.Stack('apiKey', ' +', 'environment');
expect(stack, equals(null));
} catch (e) {
print('Error from stack initialization without Delivery Token : $e');
}
});
test('stack initialization without Environment name', () {
try {
final stack = contentstack.Stack('apiKey', 'apiKey', '} ');
expect(stack, equals(null));
} catch (e) {
print('Error from stack initialization without Environment name : $e');
}
});
// test('stack fetch getContentTypes', () async {
// final queryParameters = {'include_count': 'true'};
// final resp = await stack.getContentTypes(queryParameters);
// if (resp is Map) {
// expect(true, resp.containsKey('content_types'));
// }
// //logger.i(resp);
// });
test('testcases setHeader', () {
final result = stack..setHeader('header1', 'headerValue');
final finalResult = result..headers!['header1'];
expect(true, finalResult.headers!.containsKey('header1'));
});
test('testcases setHeader', () {
stack
..setHeader('header1', 'headerValue1')
..setHeader('header2', 'headerValue2')
..removeHeader('header2');
expect(false, stack.headers!.containsKey('header2'));
});
});
group('Group of testcases for ContentType', () {
test('test content type urlPath', () {
final contentType = stack.contentType('application_theme');
expect('/v3/content_types/application_theme', contentType.urlPath);
});
test('testcases instance of the content type', () {
final contentType = stack.contentType('application_theme');
// ignore: unnecessary_type_check
expect(true, contentType is contentstack.ContentType);
});
test('testcases content type fetch uid', () async {
final contentType = stack.contentType('application_theme');
await contentType.fetch().then((response) {
expect(response['error_code'] != null, true);
});
});
test('testcases content_type_uid is missing', () async {
try {
final contentType = stack.contentType('application_theme');
// ignore: cascade_invocations
contentType.urlPath = null;
await contentType.fetch().then((response) {}).catchError((error) {
expect(error.message, equals('content_type_uid is missing'));
});
} catch (e) {
print('Error from testcases content_type_uid is missing : $e');
}
});
test('testcases queryParams.isNotEmpty', () async {
final contentType = stack.contentType('application_theme');
final params = {'keyOne': 'valueOne', 'keyTwo': 'valueTwo'};
await contentType.fetch(params).then((response) {
expect(15, response['content_type']['schema'].length);
}).catchError((error) {
expect(error != null, true);
});
});
});
group('testcase for URLQueryParams', () {
test('test query_params', () {
final params = URLQueryParams()..append('key', 'value');
final url = params.toUrl('cdn.contentstack.io');
expect('cdn.contentstack.io?key=value', url);
});
test('query_params', () {
final params = URLQueryParams()
..append('key', 'value')
..append('key1', 'value1')
..remove('key');
final url = params.toUrl('cdn.contentstack.io');
expect('cdn.contentstack.io?key1=value1', url);
});
test('global fields without params', () {
final response = stack.globalField();
print(response);
});
test('Global fields with parameters', () {
final response = stack.globalField('sso', false);
print(response);
});
test('Global fields with parameters', () {
final response = stack.globalField('sso', true);
print(response);
});
});
}