Start test migrations

This commit is contained in:
Alexandre Bodin 2023-09-05 10:46:03 +02:00
parent a1a2c76ae7
commit 6a17aa5ac8
9 changed files with 38 additions and 32 deletions

View File

@ -1,4 +1,12 @@
module.exports = {
root: true,
extends: ['custom/back/typescript'],
overrides: [
{
files: ['**/*.test.ts'],
rules: {
'import/no-relative-packages': 'warn',
},
},
],
};

View File

@ -143,6 +143,7 @@
"@types/bcryptjs": "2.4.3",
"@types/configstore": "5.0.1",
"@types/delegates": "1.0.0",
"@types/jest": "29.5.2",
"@types/koa": "*",
"@types/koa-compress": "4.0.3",
"@types/koa-session": "6.4.1",

View File

@ -1,4 +1,4 @@
import './global';
import './admin';
import strapiFactory from './Strapi';
export = strapiFactory;

View File

@ -1,8 +1,6 @@
'use strict';
const crypto = require('crypto');
const { generateAdminUserHash } = require('../admin-user-hash');
const createContext = require('../../../../../../../test/helpers/create-context');
import crypto from 'crypto';
import { generateAdminUserHash } from '../admin-user-hash';
import createContext from '../../../../../../../test/helpers/create-context';
describe('user email hash', () => {
test('should create a hash from admin user email', () => {
@ -22,7 +20,7 @@ describe('user email hash', () => {
const hash = crypto.createHash('sha256').update('testemail@strapi.io').digest('hex');
const userId = generateAdminUserHash(strapi);
const userId = generateAdminUserHash(strapi as any);
expect(userId).toBe(hash);
});
@ -35,7 +33,7 @@ describe('user email hash', () => {
},
};
const userId = generateAdminUserHash(strapi);
const userId = generateAdminUserHash(strapi as any);
expect(userId).toBe('');
});
});

View File

@ -1,10 +1,8 @@
'use strict';
import { get } from 'lodash/fp';
import metrics from '../index';
jest.mock('node-fetch', () => jest.fn(() => Promise.resolve()));
const { get } = require('lodash/fp');
const metrics = require('../index');
const fetch = jest.fn(() => Promise.resolve());
describe('metrics', () => {
@ -37,7 +35,7 @@ describe('metrics', () => {
get: jest.fn(() => ({})),
},
fetch,
});
} as any);
metricsInstance.register();
@ -72,7 +70,7 @@ describe('metrics', () => {
get: jest.fn(() => ({})),
},
fetch,
});
} as any);
metricsInstance.register();
@ -105,21 +103,24 @@ describe('metrics', () => {
get: jest.fn(() => ({})),
},
fetch,
});
} as any);
send('someEvent');
expect(fetch).toHaveBeenCalled();
expect(fetch.mock.calls[0][0]).toBe('https://analytics.strapi.io/api/v2/track');
expect(fetch.mock.calls[0][1].method).toBe('POST');
expect(JSON.parse(fetch.mock.calls[0][1].body)).toMatchObject({
const callParameters = fetch.mock.calls[0] as any[];
expect(callParameters[0]).toBe('https://analytics.strapi.io/api/v2/track');
expect(callParameters[1].method).toBe('POST');
expect(JSON.parse(callParameters[1].body)).toMatchObject({
event: 'someEvent',
groupProperties: {
projectType: 'Community',
projectId: 'test',
},
});
expect(fetch.mock.calls[0][1].headers).toMatchObject({
expect(callParameters[1].headers).toMatchObject({
'Content-Type': 'application/json',
'X-Strapi-Event': 'someEvent',
});
@ -152,7 +153,7 @@ describe('metrics', () => {
get: jest.fn(() => ({})),
},
fetch,
});
} as any);
send('someEvent');

View File

@ -1,6 +1,4 @@
'use strict';
const isTruthyEnvVar = require('../is-truthy');
import isTruthyEnvVar from '../is-truthy';
describe('isTruthyEnvVar', () => {
test('Handles boolean strings', () => {

View File

@ -8,7 +8,7 @@ export type BigInteger = Attribute.OfType<'biginteger'> &
Attribute.PrivateOption &
Attribute.RequiredOption &
Attribute.WritableOption &
Attribute.VisibleOption
Attribute.VisibleOption;
export type BigIntegerValue = string;

View File

@ -1,4 +1,4 @@
import type { Utils } from '@strapi/strapi';
import type { Utils } from '..';
/**
* Assign a default value `TDefault` to `TValue` if `TValue` is of type `never`

View File

@ -2452,12 +2452,12 @@ __metadata:
languageName: node
linkType: hard
"@casl/ability@npm:5.4.4":
version: 5.4.4
resolution: "@casl/ability@npm:5.4.4"
"@casl/ability@npm:6.5.0":
version: 6.5.0
resolution: "@casl/ability@npm:6.5.0"
dependencies:
"@ucast/mongo2js": ^1.3.0
checksum: d7afcf09fdd03b1908bdf009246b76327f19cf26b16d235d331231f5ad40fde51d42567fe669143c383627177f547585d6d99486eb4d4b98171cde67b5ee4cd2
checksum: 3e5e415ea1c8e5a0865825caea01ab4c146a78888f5efb00a6241957f3141eeb2ccd603acc6a4fc10c401c75b04543bcfc20c22b65d95da32f6b2ea081cfcf2d
languageName: node
linkType: hard
@ -6950,7 +6950,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@strapi/admin@workspace:packages/core/admin"
dependencies:
"@casl/ability": 5.4.4
"@casl/ability": 6.5.0
"@pmmmwh/react-refresh-webpack-plugin": 0.5.10
"@strapi/data-transfer": 4.12.7
"@strapi/design-system": 1.9.0
@ -7055,7 +7055,6 @@ __metadata:
resolution: "@strapi/data-transfer@workspace:packages/core/data-transfer"
dependencies:
"@strapi/logger": 4.12.7
"@strapi/strapi": 4.12.7
"@types/fs-extra": 9.0.13
"@types/jest": 29.5.2
"@types/koa": "*"
@ -7271,7 +7270,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@strapi/permissions@workspace:packages/core/permissions"
dependencies:
"@casl/ability": 5.4.4
"@casl/ability": 6.5.0
"@strapi/utils": 4.12.7
eslint-config-custom: 4.12.7
lodash: 4.17.21
@ -7723,6 +7722,7 @@ __metadata:
"@types/bcryptjs": 2.4.3
"@types/configstore": 5.0.1
"@types/delegates": 1.0.0
"@types/jest": 29.5.2
"@types/koa": "*"
"@types/koa-compress": 4.0.3
"@types/koa-session": 6.4.1