@contractkit/plugin-bruno 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { generateOpenCollection, sanitizePath, MANIFEST_FILENAME, parseManifest, mergePluginFile } from '../src/codegen-bruno.js';
3
+ import { validateBrunoExtension } from '../src/index.js';
3
4
  import {
4
5
  opRoot,
5
6
  opRoute,
@@ -1116,7 +1117,7 @@ describe('plugin file merges', () => {
1116
1117
  opRoute('/users', [
1117
1118
  opOperation('get', {
1118
1119
  responses: [opResponse(200, 'User')],
1119
- pluginFiles: { bruno: 'runtime:\n script:\n req: |\n console.log("pre");\n' },
1120
+ pluginExtensions: { bruno: { template: 'runtime:\n script:\n req: |\n console.log("pre");\n' } },
1120
1121
  }),
1121
1122
  ]),
1122
1123
  ]);
@@ -1134,17 +1135,19 @@ describe('plugin file merges', () => {
1134
1135
  opRoute('/users', [
1135
1136
  opOperation('get', {
1136
1137
  responses: [opResponse(200)],
1137
- pluginFiles: {
1138
- bruno: [
1139
- 'runtime:',
1140
- ' assertions:',
1141
- ' - expression: res.status',
1142
- ' operator: eq',
1143
- ' value: "200"',
1144
- ' - expression: res.headers["x-request-id"]',
1145
- ' operator: isDefined',
1146
- ' value: ""',
1147
- ].join('\n'),
1138
+ pluginExtensions: {
1139
+ bruno: {
1140
+ template: [
1141
+ 'runtime:',
1142
+ ' assertions:',
1143
+ ' - expression: res.status',
1144
+ ' operator: eq',
1145
+ ' value: "200"',
1146
+ ' - expression: res.headers["x-request-id"]',
1147
+ ' operator: isDefined',
1148
+ ' value: ""',
1149
+ ].join('\n'),
1150
+ },
1148
1151
  },
1149
1152
  }),
1150
1153
  ]),
@@ -1161,7 +1164,7 @@ describe('plugin file merges', () => {
1161
1164
  opRoute('/users', [
1162
1165
  opOperation('get', {
1163
1166
  responses: [opResponse(200)],
1164
- pluginFiles: { bruno: 'runtime:\n script:\n req: |\n // pre\n' },
1167
+ pluginExtensions: { bruno: { template: 'runtime:\n script:\n req: |\n // pre\n' } },
1165
1168
  }),
1166
1169
  ]),
1167
1170
  ]);
@@ -1172,13 +1175,13 @@ describe('plugin file merges', () => {
1172
1175
  expect(req.content).toContain('url:');
1173
1176
  });
1174
1177
 
1175
- it('leaves generated content unchanged when pluginFiles is absent', () => {
1178
+ it('leaves generated content unchanged when pluginExtensions is absent', () => {
1176
1179
  const withoutOverride = opRoot([opRoute('/users', [opOperation('get', { responses: [opResponse(200)] })])]);
1177
1180
  const withOverride = opRoot([
1178
1181
  opRoute('/users', [
1179
1182
  opOperation('get', {
1180
1183
  responses: [opResponse(200)],
1181
- pluginFiles: {},
1184
+ pluginExtensions: {},
1182
1185
  }),
1183
1186
  ]),
1184
1187
  ]);
@@ -1193,7 +1196,7 @@ describe('plugin file merges', () => {
1193
1196
  opRoute('/users', [
1194
1197
  opOperation('get', {
1195
1198
  responses: [opResponse(200)],
1196
- pluginFiles: { bruno: 'just a scalar string' },
1199
+ pluginExtensions: { bruno: { template: 'just a scalar string' } },
1197
1200
  }),
1198
1201
  ]),
1199
1202
  ]);
@@ -1206,7 +1209,7 @@ describe('plugin file merges', () => {
1206
1209
  const root = opRoot([
1207
1210
  opRoute('/users', [
1208
1211
  opOperation('get', {
1209
- pluginFiles: { bruno: 'info:\n name: Custom Name\n' },
1212
+ pluginExtensions: { bruno: { template: 'info:\n name: Custom Name\n' } },
1210
1213
  }),
1211
1214
  ]),
1212
1215
  ]);
@@ -1253,3 +1256,33 @@ describe('mergePluginFile', () => {
1253
1256
  });
1254
1257
  });
1255
1258
 
1259
+ describe('validateBrunoExtension', () => {
1260
+ it('accepts an empty object', () => {
1261
+ expect(validateBrunoExtension({})).toBeUndefined();
1262
+ });
1263
+
1264
+ it('accepts { template: <string> }', () => {
1265
+ expect(validateBrunoExtension({ template: 'runtime: {}' })).toBeUndefined();
1266
+ });
1267
+
1268
+ it('rejects a non-object value', () => {
1269
+ const result = validateBrunoExtension('foo') as { errors: string[] };
1270
+ expect(result.errors[0]).toContain('expected an object');
1271
+ });
1272
+
1273
+ it('rejects an array value', () => {
1274
+ const result = validateBrunoExtension(['x']) as { errors: string[] };
1275
+ expect(result.errors[0]).toContain('array');
1276
+ });
1277
+
1278
+ it('rejects template that is not a string', () => {
1279
+ const result = validateBrunoExtension({ template: 7 }) as { errors: string[] };
1280
+ expect(result.errors[0]).toContain("'template' must be a string");
1281
+ });
1282
+
1283
+ it('rejects unknown fields', () => {
1284
+ const result = validateBrunoExtension({ template: 'x', other: 'y' }) as { errors: string[] };
1285
+ expect(result.errors[0]).toContain("unknown field 'other'");
1286
+ });
1287
+ });
1288
+