forked from mckaywrigley/chatbot-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🐛 fix import (mckaywrigley#224) * 🐛 fix import of corrupted history see mckaywrigley#224 (comment) * add the run-test-suite github action
- Loading branch information
1 parent
5aa5be3
commit b0c289f
Showing
15 changed files
with
13,868 additions
and
6,862 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.env | ||
.env.local | ||
node_modules | ||
|
||
test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Run Jest Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: node:16 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run Jest Test Suite | ||
run: npm test | ||
|
||
- name: Publish Test Report | ||
if: always() | ||
uses: EnricoMi/publish-unit-test-result-action@v1 | ||
with: | ||
files: test-results/**/results.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
# testing | ||
/coverage | ||
/test-results | ||
|
||
# next.js | ||
/.next/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { ExportFormatV1, ExportFormatV2 } from '@/types/export'; | ||
import { OpenAIModels, OpenAIModelID } from '@/types/openai'; | ||
import { DEFAULT_SYSTEM_PROMPT } from '@/utils/app/const'; | ||
import { | ||
cleanData, | ||
isExportFormatV1, | ||
isExportFormatV2, | ||
isExportFormatV3, | ||
isLatestExportFormat, | ||
} from '@/utils/app/importExport'; | ||
|
||
describe('Export Format Functions', () => { | ||
describe('isExportFormatV1', () => { | ||
it('should return true for v1 format', () => { | ||
const obj = [{ id: 1 }]; | ||
expect(isExportFormatV1(obj)).toBe(true); | ||
}); | ||
|
||
it('should return false for non-v1 formats', () => { | ||
const obj = { version: 3, history: [], folders: [] }; | ||
expect(isExportFormatV1(obj)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isExportFormatV2', () => { | ||
it('should return true for v2 format', () => { | ||
const obj = { history: [], folders: [] }; | ||
expect(isExportFormatV2(obj)).toBe(true); | ||
}); | ||
|
||
it('should return false for non-v2 formats', () => { | ||
const obj = { version: 3, history: [], folders: [] }; | ||
expect(isExportFormatV2(obj)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isExportFormatV3', () => { | ||
it('should return true for v3 format', () => { | ||
const obj = { version: 3, history: [], folders: [] }; | ||
expect(isExportFormatV3(obj)).toBe(true); | ||
}); | ||
|
||
it('should return false for non-v3 formats', () => { | ||
const obj = { version: 4, history: [], folders: [] }; | ||
expect(isExportFormatV3(obj)).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('cleanData Functions', () => { | ||
describe('cleaning v1 data', () => { | ||
it('should return the latest format', () => { | ||
const data = [ | ||
{ | ||
id: 1, | ||
name: 'conversation 1', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: "what's up ?", | ||
}, | ||
{ | ||
role: 'assistant', | ||
content: 'Hi', | ||
}, | ||
], | ||
}, | ||
] as ExportFormatV1; | ||
const obj = cleanData(data); | ||
expect(isLatestExportFormat(obj)).toBe(true); | ||
expect(obj).toEqual({ | ||
version: 3, | ||
history: [ | ||
{ | ||
id: 1, | ||
name: 'conversation 1', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: "what's up ?", | ||
}, | ||
{ | ||
role: 'assistant', | ||
content: 'Hi', | ||
}, | ||
], | ||
model: OpenAIModels[OpenAIModelID.GPT_3_5], | ||
prompt: DEFAULT_SYSTEM_PROMPT, | ||
folderId: null, | ||
}, | ||
], | ||
folders: [], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('cleaning v2 data', () => { | ||
it('should return the latest format', () => { | ||
const data = { | ||
history: [ | ||
{ | ||
id: '1', | ||
name: 'conversation 1', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: "what's up ?", | ||
}, | ||
{ | ||
role: 'assistant', | ||
content: 'Hi', | ||
}, | ||
], | ||
}, | ||
], | ||
folders: [ | ||
{ | ||
id: 1, | ||
name: 'folder 1', | ||
}, | ||
], | ||
} as ExportFormatV2; | ||
const obj = cleanData(data); | ||
expect(isLatestExportFormat(obj)).toBe(true); | ||
expect(obj).toEqual({ | ||
version: 3, | ||
history: [ | ||
{ | ||
id: '1', | ||
name: 'conversation 1', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: "what's up ?", | ||
}, | ||
{ | ||
role: 'assistant', | ||
content: 'Hi', | ||
}, | ||
], | ||
model: OpenAIModels[OpenAIModelID.GPT_3_5], | ||
prompt: DEFAULT_SYSTEM_PROMPT, | ||
folderId: null, | ||
}, | ||
], | ||
folders: [ | ||
{ | ||
id: '1', | ||
name: 'folder 1', | ||
type: 'chat', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Config } from 'jest'; | ||
|
||
const config: Config = { | ||
testEnvironment: 'jest-environment-jsdom', | ||
verbose: true, | ||
preset: 'ts-jest', | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/$1', | ||
}, | ||
reporters: [ | ||
'default', | ||
[ | ||
'jest-junit', | ||
{ | ||
outputDirectory: 'test-results/jest', | ||
outputName: 'results.xml', | ||
}, | ||
], | ||
], | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.