Skip to content

Commit 37ab3eb

Browse files
fix tests by adding test credentials to the loaded ones
1 parent 03d9d54 commit 37ab3eb

File tree

11 files changed

+60
-60
lines changed

11 files changed

+60
-60
lines changed

packages/@n8n/backend-test-utils/src/random.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const randomCredentialPayload = ({
4848
isGlobal,
4949
}: { isManaged?: boolean; isGlobal?: boolean } = {}): CredentialPayload => ({
5050
name: randomName(),
51-
type: randomName(),
51+
type: 'githubApi',
5252
data: { accessToken: randomString(6, 16) },
5353
isManaged,
5454
isGlobal,

packages/cli/test/integration/access-control/built-in-roles.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ describe('Built-in Role Matrix Testing', () => {
6060
passwordReset: jest.fn(),
6161
});
6262

63+
await utils.initCredentialsTypes();
64+
6365
// Create standard users
6466
owner = await createOwner();
6567
member1 = await createMember();

packages/cli/test/integration/access-control/cross-project-access.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ describe('Cross-Project Access Control Tests', () => {
6363
passwordReset: jest.fn(),
6464
});
6565

66+
await utils.initCredentialsTypes();
67+
6668
// Create standard users
6769
owner = await createOwner();
6870
member1 = await createMember();

packages/cli/test/integration/access-control/custom-roles-functionality.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ describe('Custom Role Functionality Tests', () => {
6767
passwordReset: jest.fn(),
6868
});
6969

70+
await utils.initCredentialsTypes();
71+
7072
// Create standard users
7173
owner = await createOwner();
7274
member1 = await createMember();

packages/cli/test/integration/access-control/resource-access-matrix.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import {
99
} from '@n8n/backend-test-utils';
1010
import type { Project, User, Role } from '@n8n/db';
1111

12+
import { UserManagementMailer } from '@/user-management/email';
13+
1214
import { createCustomRoleWithScopeSlugs, cleanupRolesAndScopes } from '../shared/db/roles';
1315
import { createOwner, createMember } from '../shared/db/users';
1416
import type { SuperAgentTest } from '../shared/types';
1517
import * as utils from '../shared/utils/';
1618

17-
import { UserManagementMailer } from '@/user-management/email';
18-
1919
const testServer = utils.setupTestServer({
2020
endpointGroups: ['workflows', 'credentials'],
2121
enabledFeatures: ['feat:sharing', 'feat:customRoles'],
2222
quotas: {
2323
'quota:maxTeamProjects': -1,
2424
},
25-
mockNodesAndCredentials: true,
2625
});
2726

2827
// Foundation users and projects
@@ -65,6 +64,8 @@ describe('Resource Access Control Matrix Tests', () => {
6564
ownerAgent = testServer.authAgentFor(owner);
6665
testUserAgent = testServer.authAgentFor(testUser);
6766

67+
await utils.initCredentialsTypes();
68+
6869
// Create custom roles with specific scopes
6970
workflowReadOnlyRole = await createCustomRoleWithScopeSlugs(
7071
['workflow:read', 'workflow:list'],

packages/cli/test/integration/ai/ai.api.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { AiService } from '@/services/ai.service';
1616

1717
import { createOwner } from '../shared/db/users';
1818
import type { SuperAgentTest } from '../shared/types';
19-
import { setupTestServer } from '../shared/utils';
19+
import { initCredentialsTypes, setupTestServer } from '../shared/utils';
2020

2121
const createAiCreditsResponse = {
2222
apiKey: randomUUID(),
@@ -30,13 +30,17 @@ Container.set(
3030
}),
3131
);
3232

33-
const testServer = setupTestServer({ endpointGroups: ['ai'], mockNodesAndCredentials: true });
33+
const testServer = setupTestServer({ endpointGroups: ['ai'] });
3434

3535
let owner: User;
3636
let ownerPersonalProject: Project;
3737

3838
let authOwnerAgent: SuperAgentTest;
3939

40+
beforeAll(async () => {
41+
await initCredentialsTypes();
42+
});
43+
4044
beforeEach(async () => {
4145
await testDb.truncate(['SharedCredentials', 'CredentialsEntity']);
4246

packages/cli/test/integration/credentials/credentials.api.ee.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const testServer = utils.setupTestServer({
4242
quotas: {
4343
'quota:maxTeamProjects': -1,
4444
},
45-
mockNodesAndCredentials: true,
4645
});
4746

4847
let owner: User;
@@ -63,6 +62,8 @@ let projectRepository: ProjectRepository;
6362

6463
beforeAll(async () => {
6564
await Container.get(RoleCacheService).refreshCache();
65+
66+
await utils.initCredentialsTypes();
6667
});
6768

6869
beforeEach(async () => {

packages/cli/test/integration/credentials/credentials.api.test.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import { Credentials } from 'n8n-core';
1818
import type { ICredentialDataDecryptedObject } from 'n8n-workflow';
1919
import { randomString } from 'n8n-workflow';
2020

21+
import { CREDENTIAL_BLANKING_VALUE } from '@/constants';
22+
import { CredentialsService } from '@/credentials/credentials.service';
23+
import { createCredentialsFromCredentialsEntity } from '@/credentials-helper';
24+
import { CredentialsTester } from '@/services/credentials-tester.service';
25+
2126
import {
2227
decryptCredentialData,
2328
getCredentialById,
@@ -27,18 +32,12 @@ import {
2732
} from '../shared/db/credentials';
2833
import { createAdmin, createManyUsers, createMember, createOwner } from '../shared/db/users';
2934
import type { SuperAgentTest } from '../shared/types';
30-
import { setupTestServer } from '../shared/utils';
31-
32-
import { CREDENTIAL_BLANKING_VALUE } from '@/constants';
33-
import { CredentialsService } from '@/credentials/credentials.service';
34-
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
35-
import { CredentialsTester } from '@/services/credentials-tester.service';
35+
import { initCredentialsTypes, setupTestServer } from '../shared/utils';
3636

3737
const { any } = expect;
3838

3939
const testServer = setupTestServer({
4040
endpointGroups: ['credentials'],
41-
mockNodesAndCredentials: true,
4241
});
4342

4443
let owner: User;
@@ -56,6 +55,10 @@ let authAdminAgent: SuperAgentTest;
5655
let projectRepository: ProjectRepository;
5756
let sharedCredentialsRepository: SharedCredentialsRepository;
5857

58+
beforeAll(async () => {
59+
await initCredentialsTypes();
60+
});
61+
5962
beforeEach(async () => {
6063
await testDb.truncate(['SharedCredentials', 'CredentialsEntity']);
6164

@@ -796,7 +799,6 @@ describe('POST /credentials', () => {
796799
const payload = randomCredentialPayload();
797800

798801
const response = await authMemberAgent.post('/credentials').send(payload);
799-
800802
expect(response.statusCode).toBe(200);
801803

802804
const { id, name, type, data: encryptedData, scopes } = response.body.data;
@@ -1308,19 +1310,13 @@ describe('PATCH /credentials/:id', () => {
13081310
const { id, data } = response.body.data;
13091311

13101312
expect(id).toBe(savedCredential.id);
1311-
// was overwritten
1312-
expect(data.accessToken).toBe(patchPayload.data.accessToken);
13131313
// was not overwritten
13141314
const dbCredential = await getCredentialById(savedCredential.id);
1315+
const unencryptedData = createCredentialsFromCredentialsEntity(dbCredential!);
1316+
expect(unencryptedData.getData().oauthTokenData).toEqual(credential.data.oauthTokenData);
13151317

1316-
// this is required to prevent redaction of oauthTokenData
1317-
jest
1318-
.spyOn(Container.get(LoadNodesAndCredentials), 'getCredential')
1319-
.mockImplementationOnce((_credentialType) => {
1320-
throw new Error('Should not be called');
1321-
});
1322-
const unencryptedData = Container.get(CredentialsService).decrypt(dbCredential!);
1323-
expect(unencryptedData.oauthTokenData).toEqual(credential.data.oauthTokenData);
1318+
// was overwritten
1319+
expect(unencryptedData.getData().accessToken).toBe(patchPayload.data.accessToken);
13241320
});
13251321

13261322
test('should fail with invalid inputs', async () => {

packages/cli/test/integration/public-api/workflows.test.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import { Container } from '@n8n/di';
1313
import { InstanceSettings } from 'n8n-core';
1414
import type { INode } from 'n8n-workflow';
1515

16-
import { createTag } from '../shared/db/tags';
17-
import { createMemberWithApiKey, createOwnerWithApiKey } from '../shared/db/users';
18-
import type { SuperAgentTest } from '../shared/types';
19-
import * as utils from '../shared/utils/';
20-
2116
import { ActiveWorkflowManager } from '@/active-workflow-manager';
2217
import { STARTING_NODES } from '@/constants';
2318
import { ExecutionService } from '@/executions/execution.service';
2419
import { ProjectService } from '@/services/project.service.ee';
2520
import { Telemetry } from '@/telemetry';
2621

22+
import { createTag } from '../shared/db/tags';
23+
import { createMemberWithApiKey, createOwnerWithApiKey } from '../shared/db/users';
24+
import type { SuperAgentTest } from '../shared/types';
25+
import * as utils from '../shared/utils/';
26+
2727
mockInstance(Telemetry);
2828

2929
let ownerPersonalProject: Project;
@@ -34,9 +34,7 @@ let authOwnerAgent: SuperAgentTest;
3434
let authMemberAgent: SuperAgentTest;
3535
let activeWorkflowManager: ActiveWorkflowManager;
3636

37-
const testServer = utils.setupTestServer({
38-
endpointGroups: ['publicApi'],
39-
});
37+
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
4038
const license = testServer.license;
4139

4240
const globalConfig = Container.get(GlobalConfig);
@@ -452,12 +450,11 @@ describe('GET /workflows', () => {
452450
}
453451
});
454452

455-
test('should return activeVersion for all workflows', async () => {
453+
test.only('should return activeVersion for all workflows', async () => {
456454
const inactiveWorkflow = await createWorkflow({}, member);
457455
const activeWorkflow = await createWorkflowWithTriggerAndHistory({}, member);
458456

459-
const test = await authMemberAgent.post(`/workflows/${activeWorkflow.id}/activate`);
460-
console.log(test.body);
457+
await authMemberAgent.post(`/workflows/${activeWorkflow.id}/activate`);
461458

462459
const response = await authMemberAgent.get('/workflows');
463460

packages/cli/test/integration/shared/utils/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {
1212
} from 'n8n-core';
1313
import { Ftp } from 'n8n-nodes-base/credentials/Ftp.credentials';
1414
import { GithubApi } from 'n8n-nodes-base/credentials/GithubApi.credentials';
15+
import { HttpBasicAuth } from 'n8n-nodes-base/credentials/HttpBasicAuth.credentials';
16+
import { HttpHeaderAuth } from 'n8n-nodes-base/credentials/HttpHeaderAuth.credentials';
17+
import { OpenAiApi } from 'n8n-nodes-base/credentials/OpenAiApi.credentials';
1518
import { Cron } from 'n8n-nodes-base/nodes/Cron/Cron.node';
1619
import { FormTrigger } from 'n8n-nodes-base/nodes/Form/FormTrigger.node';
1720
import { ScheduleTrigger } from 'n8n-nodes-base/nodes/Schedule/ScheduleTrigger.node';
@@ -63,6 +66,18 @@ export async function initCredentialsTypes(): Promise<void> {
6366
type: new Ftp(),
6467
sourcePath: '',
6568
},
69+
openAiApi: {
70+
type: new OpenAiApi(),
71+
sourcePath: '',
72+
},
73+
httpHeaderAuth: {
74+
type: new HttpHeaderAuth(),
75+
sourcePath: '',
76+
},
77+
httpBasicAuth: {
78+
type: new HttpBasicAuth(),
79+
sourcePath: '',
80+
},
6681
};
6782
}
6883

0 commit comments

Comments
 (0)