Update all API queries to use the v7 model

This commit is contained in:
myarmolinsky 2024-09-17 07:59:06 -04:00
parent afd14794f5
commit f0e0c0d728
4 changed files with 26 additions and 27 deletions

View File

@ -152,8 +152,7 @@ export const createRelease = async function (
},
},
{
// @balena/compose atm works with v6, bump it once @balena/compose moves to v7.
apiVersion: 'v6',
apiVersion: 'v7',
},
);

View File

@ -388,7 +388,7 @@ describe('balena deploy', function () {
let failedImagePatchRequests = 0;
let succesfullImagePatchRequests = 0;
api
.optPatch(/^\/v6\/image($|[(?])/, { times: maxRequestRetries })
.optPatch(/^\/v7\/image($|[(?])/, { times: maxRequestRetries })
.reply((_uri, requestBody) => {
const imageBody = requestBody as Partial<
import('@balena/compose/dist/release/models').ImageModel

View File

@ -46,7 +46,7 @@ describe('balena device', function () {
it('should list device details for provided uuid', async () => {
api.scope
.get(
/^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/,
/^\/v7\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/,
)
.replyWithFile(200, path.join(apiResponsePath, 'device.json'), {
'Content-Type': 'application/json',
@ -64,7 +64,7 @@ describe('balena device', function () {
it.skip('correctly handles devices with missing fields', async () => {
api.scope
.get(
/^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/,
/^\/v7\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/,
)
.replyWithFile(
200,
@ -88,7 +88,7 @@ describe('balena device', function () {
// e.g. When user has a device associated with app that user is no longer a collaborator of.
api.scope
.get(
/^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/,
/^\/v7\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/,
)
.replyWithFile(
200,
@ -109,7 +109,7 @@ describe('balena device', function () {
it('outputs device as JSON with the -j/--json flag', async () => {
api.scope
.get(/^\/v6\/device\?.+&\$expand=device_tag\(\$select=tag_key,value\)/)
.get(/^\/v7\/device\?.+&\$expand=device_tag\(\$select=tag_key,value\)/)
.replyWithFile(200, path.join(apiResponsePath, 'device.json'), {
'Content-Type': 'application/json',
});
@ -125,7 +125,7 @@ describe('balena device', function () {
it('should list devices from own and collaborator apps', async () => {
api.scope
.get(
'/v6/device?$orderby=device_name%20asc&$select=id,uuid,device_name,status,is_online,supervisor_version,os_version&$expand=belongs_to__application($select=app_name,slug),is_of__device_type($select=slug),is_running__release($select=commit)',
'/v7/device?$orderby=device_name%20asc&$select=id,uuid,device_name,status,is_online,supervisor_version,os_version&$expand=belongs_to__application($select=app_name,slug),is_of__device_type($select=slug),is_running__release($select=commit)',
)
.replyWithFile(200, path.join(apiResponsePath, 'devices.json'), {
'Content-Type': 'application/json',

View File

@ -39,7 +39,7 @@ export class BalenaAPIMock extends NockMock {
times = undefined as number | undefined,
expandArchitecture = false,
} = {}) {
const interceptor = this.optGet(/^\/v6\/application($|[(?])/, {
const interceptor = this.optGet(/^\/v7\/application($|[(?])/, {
optional,
persist,
times,
@ -52,8 +52,8 @@ export class BalenaAPIMock extends NockMock {
path.join(
apiResponsePath,
!expandArchitecture
? 'application-GET-v6-expanded-app-type.json'
: 'application-GET-v6-expanded-app-type-cpu-arch.json',
? 'application-GET-v7-expanded-app-type.json'
: 'application-GET-v7-expanded-app-type-cpu-arch.json',
),
jHeader,
);
@ -87,7 +87,7 @@ export class BalenaAPIMock extends NockMock {
}
public expectGetMyApplication(opts: ScopeOpts = {}) {
this.optGet(/^\/v6\/my_application($|[(?])/, opts).reply(
this.optGet(/^\/v7\/my_application($|[(?])/, opts).reply(
200,
JSON.parse(`{"d": [{
"organization": [{ "handle": "bob", "__metadata": {} }],
@ -109,7 +109,7 @@ export class BalenaAPIMock extends NockMock {
persist = false,
times = undefined as number | undefined,
} = {}) {
const interceptor = this.optGet(/^\/v6\/release($|[(?])/, {
const interceptor = this.optGet(/^\/v7\/release($|[(?])/, {
persist,
optional,
times,
@ -117,12 +117,12 @@ export class BalenaAPIMock extends NockMock {
if (notFound) {
interceptor.reply(200, { d: [] });
} else {
this.optGet(/^\/v6\/release($|[(?])/, {
this.optGet(/^\/v7\/release($|[(?])/, {
persist,
optional,
}).replyWithFile(
200,
path.join(apiResponsePath, 'release-GET-v6.json'),
path.join(apiResponsePath, 'release-GET-v7.json'),
jHeader,
);
}
@ -139,7 +139,7 @@ export class BalenaAPIMock extends NockMock {
persist = false,
times = undefined as number | undefined,
}) {
this.optPatch(/^\/v6\/release($|[(?])/, { optional, persist, times }).reply(
this.optPatch(/^\/v7\/release($|[(?])/, { optional, persist, times }).reply(
statusCode,
this.getInspectedReplyBodyFunction(inspectRequest, replyBody),
);
@ -155,11 +155,11 @@ export class BalenaAPIMock extends NockMock {
persist = false,
times = undefined as number | undefined,
}) {
this.optPost(/^\/v6\/release($|[(?])/, { optional, persist, times }).reply(
this.optPost(/^\/v7\/release($|[(?])/, { optional, persist, times }).reply(
statusCode,
this.getInspectedReplyFileFunction(
inspectRequest,
path.join(apiResponsePath, 'release-POST-v6.json'),
path.join(apiResponsePath, 'release-POST-v7.json'),
),
jHeader,
);
@ -176,7 +176,7 @@ export class BalenaAPIMock extends NockMock {
persist = false,
times = undefined as number | undefined,
}) {
this.optPatch(/^\/v6\/image($|[(?])/, { optional, persist, times }).reply(
this.optPatch(/^\/v7\/image($|[(?])/, { optional, persist, times }).reply(
statusCode,
this.getInspectedReplyBodyFunction(inspectRequest, replyBody),
);
@ -186,9 +186,9 @@ export class BalenaAPIMock extends NockMock {
* Mocks balena-release call
*/
public expectPostImage(opts: ScopeOpts = {}) {
this.optPost(/^\/v6\/image($|[(?])/, opts).replyWithFile(
this.optPost(/^\/v7\/image($|[(?])/, opts).replyWithFile(
201,
path.join(apiResponsePath, 'image-POST-v6.json'),
path.join(apiResponsePath, 'image-POST-v7.json'),
jHeader,
);
}
@ -197,9 +197,9 @@ export class BalenaAPIMock extends NockMock {
* Mocks balena-release call
*/
public expectPostImageLabel(opts: ScopeOpts = {}) {
this.optPost(/^\/v6\/image_label($|[(?])/, opts).replyWithFile(
this.optPost(/^\/v7\/image_label($|[(?])/, opts).replyWithFile(
201,
path.join(apiResponsePath, 'image-label-POST-v6.json'),
path.join(apiResponsePath, 'image-label-POST-v7.json'),
jHeader,
);
}
@ -209,11 +209,11 @@ export class BalenaAPIMock extends NockMock {
*/
public expectPostImageIsPartOfRelease(opts: ScopeOpts = {}) {
this.optPost(
/^\/v6\/image__is_part_of__release($|[(?])/,
/^\/v7\/image__is_part_of__release($|[(?])/,
opts,
).replyWithFile(
200,
path.join(apiResponsePath, 'image-is-part-of-release-POST-v6.json'),
path.join(apiResponsePath, 'image-is-part-of-release-POST-v7.json'),
jHeader,
);
}
@ -365,7 +365,7 @@ export class BalenaAPIMock extends NockMock {
public expectGetDeviceTypes(opts: ScopeOpts = {}) {
this.optGet(/^\/v\d+\/device_type($|\?)/, opts).replyWithFile(
200,
path.join(apiResponsePath, 'device-type-GET-v6.json'),
path.join(apiResponsePath, 'device-type-GET-v7.json'),
jHeader,
);
}
@ -404,7 +404,7 @@ export class BalenaAPIMock extends NockMock {
serviceName: string;
}) {
const serviceId = opts.serviceId || 243768;
this.optGet(/^\/v6\/application($|\?).*\$expand=service.*/, opts).reply(
this.optGet(/^\/v7\/application($|\?).*\$expand=service.*/, opts).reply(
200,
{
d: [{ service: [{ id: serviceId, service_name: opts.serviceName }] }],