Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More integration tests, New github action to run integration tests #602

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7b2e671
datasource upload, nonfunctional upload
NaderRNA Oct 2, 2024
2af7068
Merge branch 'develop' into more-integration-tests
NaderRNA Oct 2, 2024
d50ede7
file successfully uploads, test not completed
NaderRNA Oct 3, 2024
8bdca7b
package-lock.json changes
NaderRNA Oct 3, 2024
a93a890
successful file upload test, adding agent tests
NaderRNA Oct 3, 2024
195f8a1
lint
NaderRNA Oct 3, 2024
51d423e
wip
NaderRNA Oct 3, 2024
4176a8f
Merge branch 'develop' into more-integration-tests
tomlynchRNA Oct 3, 2024
f404bad
modifying all tests to delete any objects created within the test to …
NaderRNA Oct 4, 2024
ca1115c
Merge branch 'develop' into more-integration-tests
NaderRNA Oct 4, 2024
e183983
Merge branch 'develop' into more-integration-tests
NaderRNA Oct 7, 2024
dca9d06
Merge branch 'more-integration-tests' of github.com:rnadigital/agentc…
NaderRNA Oct 7, 2024
1174085
modifying .env.example to work with integration tests, including scri…
NaderRNA Oct 8, 2024
86e5301
Create webapp-integration-tests.yml
NaderRNA Oct 8, 2024
9271db3
fixing merge conflicts
NaderRNA Oct 8, 2024
01c6538
Update webapp-integration-tests.yml
NaderRNA Oct 8, 2024
98a0a6d
adding .env.example to vector-db-proxy
NaderRNA Oct 8, 2024
084341e
Merge branch 'more-integration-tests' of github.com:rnadigital/agentc…
NaderRNA Oct 8, 2024
935d182
fixing terminal issue in github action
NaderRNA Oct 8, 2024
e91a834
adding firefox support to action
NaderRNA Oct 8, 2024
f4d29d9
adding install.sh back into the action
NaderRNA Oct 8, 2024
42b1169
fixing dockercompose issues
NaderRNA Oct 8, 2024
44a4e47
slightly modifying test file before merging develop into this branch
NaderRNA Oct 10, 2024
4a5ddb6
adding another agent test
NaderRNA Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webapp/src/lib/middleware/auth/checksession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export default function checkSession(req, res, next) {
if (!res.locals.account?._id && !res.locals.isAgentBackend) {
// console.log("checkSession, reslocals: ", res.locals);
console.log("checkSession, reslocals: ", res.locals);
Fixed Show fixed Hide fixed
if (res.locals.isSocket) {
return res?.locals?.socket?.disconnect();
} else {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/lib/middleware/auth/fetchsession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
export default async function fetchSession(req, res, next) {
// log('req.session:', req.session);
if (req.session && (req.session.accountId || req.session.passport?.user)) {
log("req.session.account", req.session.accountId);
Fixed Show fixed Hide fixed
let account: Account;
if (req.session.accountId) {
account = await getAccountById(req.session.accountId);
} else if (req.session.passport?.user) {
const { oauthId, provider } = req.session.passport?.user;
account = await getAccountByOAuthOrEmail(oauthId, provider, null);
}
// log('account:', account);
log('account:', account);
if (account) {
res.locals.account = {
_id: account._id.toString(),
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/sync-server/ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
DEBUG: 'sync-server:main',
DEBUG_COLORS: true
}
},
}
// {
// script: 'npm run dev:sync-worker',
// watch: true,
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/test/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ beforeAll(async () => {

describe('account tests', () => {

test('register new accounts', async () => {
test.only('register new accounts', async () => {
let response = await fetch(`${process.env.WEBAPP_TEST_BASE_URL}/forms/account/register`, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('account tests', () => {
await db.db().collection('accounts').deleteMany({ email: accountDetails.account3_email }); //delete these accounts so we can stress test logins in the next test
}, 60 * SECONDS); //extended timeout due to multiple account creations

test('stress test registration with many accounts', async () => {
test.only('stress test registration with many accounts', async () => {
const accounts = [
{ name: accountDetails.account1_name, email: accountDetails.account1_email, password: accountDetails.account1_password },
{ name: accountDetails.account2_name, email: accountDetails.account2_email, password: accountDetails.account2_password },
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('account tests', () => {


//TODO: refactor this to do it with a loop
test('login as new users - 11 logins', async () => {
test.only('login as new users - 11 logins', async () => {
let response = await fetch(`${process.env.WEBAPP_TEST_BASE_URL}/forms/account/login`, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('account tests', () => {
}, 60 * SECONDS); // extended timeout due to multiple account logins


test('get account', async () => {
test.only('get account', async () => {
const url = `${process.env.WEBAPP_TEST_BASE_URL}/account.json`;
const accounts = [
{ email: accountDetails.account1_email, sessionCookie: sessionCookie1 },
Expand Down Expand Up @@ -353,7 +353,7 @@ describe('account tests', () => {
//test with valid token??

//sets the role to prevent redirects to onboarding in further tests
test('set role - onboarding', async () => {
test.only('set role - onboarding', async () => {
const accounts = [
accountDetails.account1_email,
accountDetails.account2_email,
Expand Down
56 changes: 56 additions & 0 deletions webapp/src/test/agents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
import * as db from '../db/index';
import { addTeam, getTeamById, getTeamWithMembers } from '../db/team';
import { getAccountByEmail, setStripeCustomerId, setStripePlan } from '../db/account';
import { SubscriptionPlan } from '../lib/struct/billing';
import { getInitialData, makeFetch, fetchTypes, accountDetails, setInitialData, updateAllAccountCsrf } from './helpers';
import dotenv from 'dotenv';
import { URLSearchParams } from 'url';
import toObjectId from '../lib/misc/toobjectid';
import { ModelList, ModelType } from '../lib/struct/model';
import { ShareLinkTypes } from '../lib/struct/sharelink';
import { getToolsByTeam } from "../db/tool";
import { TeamRoles } from "../lib/permissions/roles"
import {Retriever} from '../lib/struct/tool';
import path from 'path';
import { defaultChunkingOptions } from '../lib/misc/defaultchunkingoptions';


beforeAll(()=>{
updateAllAccountCsrf();
})

describe("Agents Tests", () => {
test.only("Add an agent", async ()=>{

});

test.only("Update an agent", async ()=>{

});

test.only("Can't add agent without permissions", async ()=>{

});

test.only("Can't edit agent without permissions", async ()=>{

});

test.only("Add an agent with invalid body", async ()=>{

});

test.only("Edit an agent with invalid body", async ()=>{

});

test.only("Add multiple agents", async ()=>{

});

test.only("Get agents (agents.json)", async ()=>{

});

})
99 changes: 99 additions & 0 deletions webapp/src/test/datasources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
import * as db from '../db/index';
import { addTeam, getTeamById, getTeamWithMembers } from '../db/team';
import { getAccountByEmail, setStripeCustomerId, setStripePlan } from '../db/account';
import { SubscriptionPlan } from '../lib/struct/billing';
import { getInitialData, makeFetch, fetchTypes, accountDetails, setInitialData, updateAllAccountCsrf } from './helpers';
import dotenv from 'dotenv';
import { URLSearchParams } from 'url';
import toObjectId from '../lib/misc/toobjectid';
import { ModelList, ModelType } from '../lib/struct/model';
import { ShareLinkTypes } from '../lib/struct/sharelink';
import { getToolsByTeam } from "../db/tool";
import { TeamRoles } from "../lib/permissions/roles"
import {Retriever} from '../lib/struct/tool';
import path from 'path';
import { defaultChunkingOptions } from '../lib/misc/defaultchunkingoptions';
//look in components/DropZone to see how the multipart form is created and how the file is uploaded
//use Fast Embed to reduce token usage for us and to also
//use a self hosted runner in git to automate the tests into the PR process
beforeAll(()=>{
updateAllAccountCsrf();
})

describe("Datasource Tests", () => {

test.only("Upload a file", async ()=>{
const account1Object = await getInitialData(accountDetails.account1_email);
//create model to be used for embedding
let url = `${process.env.WEBAPP_TEST_BASE_URL}/${account1Object.resourceSlug}/forms/model/add`;
let config = {
model: 'fast-bge-small-en',
api_key: 'abcdefg'
}
let body = {
name: 'testModel1',
model: 'fast-bge-small-en',
config: config,
type: ModelType.FASTEMBED
};

let response = await makeFetch(
url,
fetchTypes.POST,
accountDetails.account1_email,
body
);

expect(response.status).toBe(200);

let responseJson = await response.json();

expect(responseJson?._id).toBeDefined();

const modelId = responseJson?._id;

const formData = new FormData();
const fs = require('fs');
const chunkingConfig = defaultChunkingOptions

formData.set('resourceSlug', account1Object.resourceSlug as string);
formData.set('modelId', modelId as string);
formData.set('datasourceDescription', "File Upload Test Datasource");
formData.set('name', "TestSource");
formData.set('retriever', Retriever.RAW as string);
formData.set('_csrf', account1Object.csrfToken as string);
const filepath = path.resolve(__dirname, 'fileUpload.txt');
const file = fs.readFileSync(filepath);

formData.append('file', new Blob([file]), 'uploadTest.txt')
Object.entries(chunkingConfig).forEach(([key, value]) => {
if (value != null) {
formData.set(key, value as string);
}
});

url = `${process.env.WEBAPP_TEST_BASE_URL}/${account1Object.resourceSlug}/forms/datasource/upload`;

response = await fetch(url, {
headers: {
cookie : account1Object.sessionCookie
},
method: 'POST',
body: formData
})

expect(response.status).toBe(200);

responseJson = await response.json();

console.log(responseJson);

expect(responseJson?.datasourceId).toBeDefined();
});


test.only("Make Connection", async () => {//make a connection with airbyte

})
});
1 change: 1 addition & 0 deletions webapp/src/test/fileUpload.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simon Says: "1+1 actually equals 4 :D"
1 change: 1 addition & 0 deletions webapp/src/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import './account';
import './pages';
import './teams';
import './models';
import './datasources';

import './logout'; //this MUST be last
4 changes: 2 additions & 2 deletions webapp/src/test/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ afterAll(async () => {

describe("log out and wrap up tests", ()=>{

test('log out', async () => {
test.only('log out', async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account1_email
);
Expand All @@ -57,7 +57,7 @@ describe("log out and wrap up tests", ()=>{
expect(response.status).toBe(200);
});

test('cant get account with invalidated session cookie', async () => {
test.only('cant get account with invalidated session cookie', async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account1_email
);
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/test/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Model Tests', () => {
expect(addModelResponseJson?.error).toBeDefined();
});

test("Test valid models with the FREE plan", async () => {
test.only("Test valid models with the FREE plan", async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account3_email
);
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Model Tests', () => {



test("Test valid embedding models with the FREE plan", async () => {
test.only("Test valid embedding models with the FREE plan", async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account3_email
);
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('Model Tests', () => {
expect(addModelResponseJson?.error).toBeDefined();
})

test("Test valid models with PRO plan", async () => {
test.only("Test valid models with PRO plan", async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account3_email
);
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('Model Tests', () => {


//switch the plan to TEAMS, test adding valid models that are off limits for FREE and for PRO and add custom models
test("Test all models with TEAMS plan", async ()=> {
test.only("Test all models with TEAMS plan", async ()=> {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account3_email
);
Expand Down
12 changes: 6 additions & 6 deletions webapp/src/test/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('team tests', () => {
});

//when debugging or creating tests, mark this test as ".only" to ensure a second team is created, this team is used in future.
test('add new team with correct stripe permissions', async () => {
test.only('add new team with correct stripe permissions', async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account1_email
);
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('team tests', () => {
});


test('Inviting existing account to team', async () => {
test.only('Inviting existing account to team', async () => {
const { initialData, sessionCookie, resourceSlug, csrfToken } = await getInitialData(
accountDetails.account1_email
);
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('team tests', () => {
expect(responseJson?.team?.members.length).toBe(3);
});

test('testing TEAM_MEMBER permissions', async () => {
test.only('testing TEAM_MEMBER permissions', async () => {
const account1Object = await getInitialData(
//account1 is the ORG_ADMIN
accountDetails.account1_email
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('team tests', () => {
expect(addAgentResponse?._id).toBeDefined();
});

test('testing TEAM_ADMIN permissions', async () => {
test.only('testing TEAM_ADMIN permissions', async () => {
const account1Object = await getInitialData(accountDetails.account1_email);
const account2Object = await getInitialData(accountDetails.account2_email);
const account3Object = await getInitialData(accountDetails.account3_email);
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('team tests', () => {
// const responseJson = await response.json();
});

test('removing TEAM_ADMIN from team, reinviting them again as a TEAM_MEMBER and testing permissions', async () => {
test.only('removing TEAM_ADMIN from team, reinviting them again as a TEAM_MEMBER and testing permissions', async () => {
const account1Object = await getInitialData(accountDetails.account1_email);
const account2Object = await getInitialData(accountDetails.account2_email);
const account3Object = await getInitialData(accountDetails.account3_email);
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('team tests', () => {
expect(responseJson?.error).toBe("Missing permission \"Add Team Member\"");//make sure it's a permissions error and not a stripe error etc...
});

test('cant add more than 10 members to TEAMS subscriptions plan', async () => {
test.only('cant add more than 10 members to TEAMS subscriptions plan', async () => {
const { resourceSlug } = await getInitialData(accountDetails.account1_email);
const url = `${process.env.WEBAPP_TEST_BASE_URL}/${resourceSlug}/forms/team/invite`;
const accounts = [
Expand Down
Loading