Skip to content

Commit

Permalink
feat: test filing workflow util
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoel committed Sep 27, 2024
1 parent e2100b0 commit 483caee
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qlever-llc/lf-sync",
"version": "3.1.1",
"version": "3.1.2",
"description": "Trellis LaserFiche sync service",
"main": "dist/index.js",
"type": "module",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"compile": false
},
"ignoredByWatcher": [
"watchMode.ignoredChanges": [
"test/**/snapshots"
]
},
Expand Down
10 changes: 4 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export async function updateSyncMetadata(
export function getFormattedDate(date: Date): string {
const year = date.getFullYear();
const month = (1 + date.getMonth()).toString();
const day = date.getDate().toString();
const day = (1 + date.getDate()).toString();

return `${month}/${day}/${year} 12:00:00 AM`;
}
Expand Down Expand Up @@ -328,19 +328,17 @@ export function filingWorkflow(metadata: Metadata): {filename: string, path: Pat
let ticketDate: string = '';
if (ticketId) {
const docDate = new Date(documentDate);
const year = docDate.getFullYear();
const month = (1 + docDate.getMonth()).toString();
ticketDate = `${year}-${month}`;
ticketDate = (docDate.toISOString().split('T')[0])!.slice(0,7);
}

let path : Path = join(
...([
`/FSQA/trellis/trading-partners`,
`/trellis/trading-partners`,
Entity,
shareMode,
documentType,
ticket,
ticketDate,
ticket,
].filter(i => i) as unknown as string)
) as unknown as Path;

Expand Down
4 changes: 4 additions & 0 deletions test/cws/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test('createDocument', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.create.txt',
mimetype: 'text/plain',
});
t.truthy(body.LaserficheEntryID);
try {
Expand All @@ -45,6 +46,7 @@ test('createDocument with file', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.create.file.txt',
mimetype: 'text/plain',
file,
});
t.log(await retrieveDocument(body.LaserficheEntryID));
Expand All @@ -68,6 +70,7 @@ test('retrieveDocument', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.retrieve.txt',
mimetype: 'text/plain',
});
const document = await retrieveDocument(body.LaserficheEntryID);
t.is(document.LaserficheEntryID, body.LaserficheEntryID);
Expand All @@ -87,6 +90,7 @@ test('deleteDocument', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.delete.txt',
mimetype: 'text/plain',
});
await deleteDocument(body.LaserficheEntryID);
t.pass();
Expand Down
2 changes: 2 additions & 0 deletions test/cws/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('retrieveDocumentContents Blob', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.txt',
mimetype: 'text/plain',
file,
});
const document = await retrieveDocumentContent(body.LaserficheEntryID);
Expand All @@ -45,6 +46,7 @@ test('retrieveDocumentContents Buffer', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.txt',
mimetype: 'text/plain',
file,
});
const document = await retrieveDocumentContent(body.LaserficheEntryID);
Expand Down
1 change: 1 addition & 0 deletions test/cws/entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test('moveEntry', async (t) => {
const entry = await createDocument({
path: '/',
name: 'test.move.txt',
mimetype: 'text/plain',
});
await moveEntry(entry, '/moved');
t.pass();
Expand Down
2 changes: 2 additions & 0 deletions test/cws/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test('setMetadata', async (t) => {
const document = await createDocument({
path: '/',
name: 'test.create.txt',
mimetype: 'text/plain',
});
await setMetadata(document, { Author: 'Trellis Test' }, 'General');
const body = await getMetadata(document);
Expand All @@ -54,6 +55,7 @@ test('setTemplate', async (t) => {
const document = await createDocument({
path: '/',
name: 'test.create2.txt',
mimetype: 'text/plain',
});
await setTemplate(document, 'General');
const body = await getMetadata(document);
Expand Down
3 changes: 3 additions & 0 deletions test/cws/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test('small upload', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.stream.txt',
mimetype: 'text/plain',
});
t.log(await retrieveDocument(body.LaserficheEntryID));
await smallUpload(body.LaserficheEntryID, file);
Expand All @@ -56,6 +57,7 @@ test('stream upload', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.stream.txt',
mimetype: 'text/plain',
});
const upload = streamUpload(
body.LaserficheEntryID,
Expand All @@ -82,6 +84,7 @@ test.failing('chunked upload', async (t) => {
const body = await createDocument({
path: '/',
name: 'test.chunked.txt',
mimetype: 'text/plain',
});
const upload = chunkedUpload(body.LaserficheEntryID);
await pipeline(contents, Duplex.from(upload), new PassThrough());
Expand Down
2 changes: 2 additions & 0 deletions test/cws/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test('smallUpload', async (t) => {
const { LaserficheEntryID: id } = await createDocument({
path: '/../../_Incoming',
name: 'test.workflow.small.pdf',
mimetype: 'application/pdf',
template: 'SFI Template 1',
metadata: {
'Document Date': new Date().toISOString(),
Expand Down Expand Up @@ -69,6 +70,7 @@ test('streamUpload', async (t) => {
const { LaserficheEntryID: id } = await createDocument({
path: '/../../_Incoming',
name: 'test.workflow.stream.pdf',
mimetype: 'application/pdf',
template: 'SFI Template 1',
metadata: {
'Document Date': new Date().toISOString(),
Expand Down
67 changes: 67 additions & 0 deletions test/filingWorkflow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @license
* Copyright 2022 Qlever LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import test from 'ava';

import {
filingWorkflow,
getFormattedDate
} from '../dist/utils.js';

test('filing workflow', (t) => {
let date = new Date();
let ticketMeta = {
Entity: 'Bob Foods, LLC',
'Document Type': 'Zendesk Ticket',
'Document Date': getFormattedDate(date),
'Share Mode': 'Shared to Smithfield',
'Expiration Date': getFormattedDate(date),
'Zendesk Ticket ID': '1115',
Products: ['Honey Glaze', "Brown Sugar Glaze"],
Locations: ['Location A', 'Location B'],
'Original Filename': "RandFilename-2.xyz",
}
let result = filingWorkflow(ticketMeta);

t.is(result.filename, 'RandFilename-2.xyz', 'Zendesk Ticket handling')
t.is(result.path, '/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Zendesk Ticket/Ticket1115/2024-09', 'Zendesk Ticket handling')

let docMeta = {
Entity: 'Bob Foods, LLC',
'Document Type': 'Certificate of Insurance',
'Document Date': getFormattedDate(date),
'Share Mode': 'Shared to Smithfield',
'Expiration Date': getFormattedDate(date),
Products: ['Honey Glaze', "Brown Sugar Glaze"],
Locations: ['Location A', 'Location B'],
'Original Filename': "RandFilename-2.xyz",
}
result = filingWorkflow(docMeta);
let expDate = date.toISOString().split('T')[0];

t.is(result.filename, `Bob Foods, LLC_Multi-Location_Multi-Product_Certificate of Insurance_EXP_${expDate}`, 'Non-ticket filename invalid')
t.is(result.path, '/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Certificate of Insurance', 'Non-ticket path invalid')

docMeta.Products.pop();
docMeta.Locations.pop();
//@ts-expect-error no likey delete
delete docMeta['Expiration Date'];
result = filingWorkflow(docMeta);
t.is(result.filename, `Bob Foods, LLC_Location A_Honey Glaze_Certificate of Insurance`, 'Non-ticket filename invalid')
t.is(result.path, '/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Certificate of Insurance', 'Non-ticket path invalid')
});

2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rootDir": ".",
"outDir": "../.test"
},
"include": [".", "../src/requeueNeedsReview.ts"],
"include": [".", "../src/requeueNeedsReview.ts", ".ts"],
"references": [
{
"path": "../"
Expand Down

0 comments on commit 483caee

Please sign in to comment.