Skip to content

Commit 9871481

Browse files
Merge pull request #320 from lightningrodlabs/projects-unit-tests
Write unit tests for functions in the projects/ folder
2 parents adf27d5 + dbd6cca commit 9871481

35 files changed

+460
-166
lines changed

.github/workflows/dry-run.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
npm install
2626
npm run web-install
2727
npm run electron-install
28+
npm run zod-models-install
29+
npm run zod-models-build
2830
shell: bash
2931
- name: setup for codesigning (macos only)
3032
if: ${{ runner.os == 'macOs' }}

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
npm install
3737
npm run web-install
3838
npm run electron-install
39+
npm run zod-models-install
40+
npm run zod-models-build
3941
shell: bash
4042
- name: setup for codesigning (macos only)
4143
if: ${{ runner.os == 'macOs' }}

scripts/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
# assumes that
46
# dna/workdir/projects.dna
57
# and

web/src/migrating/export.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function updateProjectMeta(
2626
export async function internalExportProjectsData(
2727
constructProjectDataFetchersFunction: typeof constructProjectDataFetchers,
2828
collectExportProjectDataFunction: typeof collectExportProjectData,
29-
_updateProjectMeta: typeof updateProjectMeta,
29+
iUpdateProjectMeta: typeof updateProjectMeta,
3030
store: any,
3131
toVersion: string,
3232
onStep: (completed: number, toComplete: number) => void,
@@ -58,7 +58,6 @@ export async function internalExportProjectsData(
5858
projectCellId
5959
)
6060
try {
61-
6261
await Promise.all([
6362
projectDataFetchers.fetchProjectMeta(),
6463
projectDataFetchers.fetchEntryPoints(),
@@ -94,7 +93,7 @@ export async function internalExportProjectsData(
9493
...projectMetaDetails,
9594
isMigrated: toVersion,
9695
}
97-
await _updateProjectMeta(newProjectMeta, actionHash, projectCellId)
96+
await iUpdateProjectMeta(newProjectMeta, actionHash, projectCellId)
9897
completedTracker++
9998
onStep(completedTracker, projectCellIds.length)
10099
}

web/src/migrating/import/cloneFunctions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { cellIdFromString } from '../../utils'
1010
import { Tag } from '../../types/tag'
1111
import { Outcome } from '../../types/outcome'
1212
import { Connection } from '../../types/connection'
13-
import { LayeringAlgorithm, ProjectMeta } from '../../types'
14-
import { ProjectMetaWithActionHash } from 'zod-models'
13+
import { ProjectMeta } from '../../types'
14+
import { LayeringAlgorithm, ProjectMetaWithActionHash } from 'zod-models'
1515

1616
export type ActionHashMap = { [oldActionHash: ActionHashB64]: ActionHashB64 }
1717

@@ -108,7 +108,7 @@ export const cloneProjectMeta = (
108108
// add a fallback layering algorithm in case the project has none
109109
layeringAlgorithm: old['layeringAlgorithm']
110110
? old['layeringAlgorithm']
111-
: "LongestPath",
111+
: LayeringAlgorithm.LongestPath,
112112
createdAt: Date.now(),
113113
creatorAgentPubKey: agentAddress,
114114
passphrase: passphrase,

web/src/migrating/import/createActionHashMapAndImportProjectData.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ProjectExportDataV1 } from 'zod-models'
12
import ProjectsZomeApi from '../../api/projectsApi'
23
import { getAppWs } from '../../hcWebsockets'
34
import { createConnection } from '../../redux/persistent/projects/connections/actions'
@@ -15,7 +16,6 @@ import {
1516
EntryPoint,
1617
} from '../../types'
1718
import { CellIdString } from '../../types/shared'
18-
import { ProjectExportDataV1 } from '../export'
1919
import {
2020
cloneDataSet,
2121
cloneTag,
@@ -30,7 +30,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
3030
projectsCellIdString: CellIdString,
3131
dispatch: any,
3232
projectsZomeApi: ProjectsZomeApi,
33-
_cloneDataSet: typeof cloneDataSet
33+
iCloneDataSet: typeof cloneDataSet
3434
) {
3535
/*
3636
outcomes, connections,
@@ -42,7 +42,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
4242

4343
// TAGS
4444
// do tags because outcomes reference them
45-
const tagActionHashMap = await _cloneDataSet<Tag>(
45+
const tagActionHashMap = await iCloneDataSet<Tag>(
4646
projectData.tags,
4747
cloneTag,
4848
projectsZomeApi.tag.create,
@@ -51,7 +51,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
5151
projectsCellIdString
5252
)
5353

54-
const outcomeActionHashMap = await _cloneDataSet<Outcome>(
54+
const outcomeActionHashMap = await iCloneDataSet<Outcome>(
5555
projectData.outcomes,
5656
// closure in the depended upon hashmap
5757
cloneOutcome(tagActionHashMap),
@@ -61,7 +61,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
6161
projectsCellIdString
6262
)
6363

64-
const connectionsActionHashMap = await _cloneDataSet<Connection>(
64+
const connectionsActionHashMap = await iCloneDataSet<Connection>(
6565
projectData.connections,
6666
// closure in the depended upon
6767
cloneConnection(outcomeActionHashMap),
@@ -71,7 +71,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
7171
projectsCellIdString
7272
)
7373

74-
const outcomeMembersActionHashMap = await _cloneDataSet<OutcomeMember>(
74+
const outcomeMembersActionHashMap = await iCloneDataSet<OutcomeMember>(
7575
projectData.outcomeMembers,
7676
// closure in the depended upon
7777
cloneData<OutcomeMember>(outcomeActionHashMap),
@@ -81,7 +81,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
8181
projectsCellIdString
8282
)
8383

84-
const outcomeCommentActionHashMap = await _cloneDataSet<OutcomeComment>(
84+
const outcomeCommentActionHashMap = await iCloneDataSet<OutcomeComment>(
8585
projectData.outcomeComments,
8686
// closure in the depended upon
8787
cloneData<OutcomeComment>(outcomeActionHashMap),
@@ -91,7 +91,7 @@ export async function internalCreateActionHashMapAndImportProjectData(
9191
projectsCellIdString
9292
)
9393

94-
const entryPointActionHashMap = await _cloneDataSet<EntryPoint>(
94+
const entryPointActionHashMap = await iCloneDataSet<EntryPoint>(
9595
projectData.entryPoints,
9696
// closure in the depended upon
9797
cloneData<EntryPoint>(outcomeActionHashMap),

web/src/migrating/import/import.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const stringToJSONSchema = z.string().transform((str, ctx): any => {
2222
export async function internalImportProjectsData(
2323
// dependencies
2424
profilesZomeApi: ProfilesZomeApi,
25-
_installProjectAndImport: typeof installProjectAndImport,
26-
_installProject: typeof installProject,
25+
iInstallProjectAndImport: typeof installProjectAndImport,
26+
iInstallProject: typeof installProject,
2727
store: any,
2828
// main input data and callbacks
2929
migrationData: string,
@@ -70,11 +70,11 @@ export async function internalImportProjectsData(
7070
// one completes
7171
for await (let projectData of projectsToMigrate) {
7272
const passphrase = projectData.projectMeta.passphrase
73-
await _installProjectAndImport(
73+
await iInstallProjectAndImport(
7474
myAgentPubKey,
7575
projectData,
7676
passphrase,
77-
store.dispatch,
77+
store.dispatch
7878
)
7979
stepsSoFar++
8080
onStep(stepsSoFar, totalSteps)
@@ -83,7 +83,7 @@ export async function internalImportProjectsData(
8383
// join each project that has already been migrated by a peer
8484
for await (let projectData of migratedProjectsToJoin) {
8585
const passphrase = projectData.projectMeta.passphrase
86-
await internalJoinProject(passphrase, store.dispatch, _installProject)
86+
await internalJoinProject(passphrase, store.dispatch, iInstallProject)
8787
stepsSoFar++
8888
onStep(stepsSoFar, totalSteps)
8989
}

web/src/projects/createProject.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ export async function internalCreateProject(
3131
agentAddress: AgentPubKeyB64,
3232
dispatch: any,
3333
iInstallProject: typeof installProject,
34+
iFinalizeCreateProject: typeof finalizeCreateProject,
3435
projectsZomeApi: ProjectsZomeApi
3536
) {
3637
const startTime = Date.now()
3738
const [cellIdString] = await iInstallProject(passphrase)
38-
await finalizeCreateProject(
39+
await iFinalizeCreateProject(
3940
cellIdString,
4041
projectMeta,
4142
agentAddress,
@@ -60,6 +61,7 @@ export async function createProject(
6061
agentAddress,
6162
dispatch,
6263
installProject,
64+
finalizeCreateProject,
6365
projectsZomeApi
6466
)
6567
}

web/src/projects/installProject.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { cellIdToString } from '../utils'
88
export async function internalInstallProject(
99
passphrase: string,
1010
adminWs: AdminWebsocket,
11+
iGetAgentPubKey: typeof getAgentPubKey
1112
): Promise<[CellIdString, CellId, string]> {
1213
const uid = passphraseToUid(passphrase)
1314
// add a bit of randomness so that
@@ -19,17 +20,21 @@ export async function internalInstallProject(
1920
const installed_app_id = `${PROJECT_APP_PREFIX}-${Math.random()
2021
.toString()
2122
.slice(-6)}-${uid}`
22-
const agent_key = getAgentPubKey()
23+
const agent_key = iGetAgentPubKey()
2324
if (!agent_key) {
2425
throw new Error(
2526
'Cannot install a new project because no AgentPubKey is known locally'
2627
)
2728
}
2829
// the dna hash HAS to act deterministically
2930
// in order for the 'joining' of Projects to work
30-
const happPath = window.require
31-
? await window.require('electron').ipcRenderer.invoke('getProjectsPath')
32-
: './happ/workdir/projects/projects.happ'
31+
let happPath: string
32+
if (typeof window !== 'undefined' && window.require)
33+
happPath = await window
34+
.require('electron')
35+
.ipcRenderer.invoke('getProjectsPath')
36+
else happPath = './happ/workdir/projects/projects.happ'
37+
3338
// INSTALL
3439
const installedApp = await adminWs.installApp({
3540
agent_key,
@@ -56,5 +61,5 @@ export async function installProject(
5661
passphrase: string
5762
): Promise<[CellIdString, CellId, string]> {
5863
const adminWs = await getAdminWs()
59-
return internalInstallProject(passphrase, adminWs)
64+
return internalInstallProject(passphrase, adminWs, getAgentPubKey)
6065
}

web/src/redux/ephemeral/animations/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default function performLayoutAnimation(
7171

7272
const projectMeta = nextState.projects.projectMeta
7373
const layeringAlgorithm =
74-
projectMeta[projectId]?.layeringAlgorithm || "LongestPath"
74+
projectMeta[projectId]?.layeringAlgorithm || LayeringAlgorithm.LongestPath
7575
// this is our final destination layout
7676
// that we'll be animating to
7777
const newLayout = layoutFormula(

web/src/redux/ephemeral/map-view-settings/reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface CollapsedOutcomesState {
1616
const defaultState: CollapsedOutcomesState = {
1717
hiddenAchievedOutcomes: [],
1818
hiddenSmallOutcomes: [],
19-
selectedLayeringAlgo: "LongestPath",
19+
selectedLayeringAlgo: LayeringAlgorithm.LongestPath,
2020
}
2121

2222
export default function (

web/src/routes/Dashboard/Dashboard.connector.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { connect } from 'react-redux'
22

33
import { getAdminWs, getAppWs } from '../../hcWebsockets'
44
import { fetchEntryPointDetails } from '../../redux/persistent/projects/entry-points/actions'
5-
import {
6-
fetchMembers,
7-
} from '../../redux/persistent/projects/members/actions'
5+
import { fetchMembers } from '../../redux/persistent/projects/members/actions'
86
import {
97
fetchProjectMeta,
108
updateProjectMeta,
@@ -118,11 +116,17 @@ function mapDispatchToProps(dispatch): DashboardDispatchProps {
118116
creatorAgentPubKey: agentAddress,
119117
createdAt: Date.now(),
120118
isImported: false,
121-
layeringAlgorithm: "CoffmanGraham",
119+
layeringAlgorithm: LayeringAlgorithm.CoffmanGraham,
122120
topPriorityOutcomes: [],
123121
isMigrated: null,
124122
}
125-
await createProject(passphrase, projectMeta, agentAddress, dispatch, projectsZomeApi)
123+
await createProject(
124+
passphrase,
125+
projectMeta,
126+
agentAddress,
127+
dispatch,
128+
projectsZomeApi
129+
)
126130
},
127131
joinProject: async (passphrase: string) => {
128132
const appWs = await getAppWs()

web/src/stories/testData/testProjectMeta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const testProject: WithActionHash<ProjectMeta> = {
88
image: null,
99
passphrase: 'testPassphrase',
1010
isImported: false,
11-
layeringAlgorithm: "CoffmanGraham",
11+
layeringAlgorithm: LayeringAlgorithm.CoffmanGraham,
1212
topPriorityOutcomes: [],
1313
isMigrated: null,
1414
actionHash: 'testProjectActionHash',

web/src/types/connection.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
import { Connection as _Connection } from 'zod-models'
1+
import {
2+
ConnectionSchema as _ConnectionSchema,
3+
Connection as _Connection,
4+
} from 'zod-models'
25

6+
export const ConnectionSchema = _ConnectionSchema
37
export type Connection = _Connection

web/src/types/entryPoint.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
import { EntryPoint as _EntryPoint } from 'zod-models'
1+
import {
2+
EntryPoint as _EntryPoint,
3+
EntryPointSchema as _EntryPointSchema,
4+
} from 'zod-models'
25

6+
export const EntryPointSchema = _EntryPointSchema
37
export type EntryPoint = _EntryPoint

web/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export * from './realtimeInfoInput'
1414
export * from './createOutcomeWithConnectionInput'
1515
export * from './createOutcomeWithConnectionOutput'
1616
export * from './deleteOutcomeFullyResponse'
17-
export * from './whoAmIOutput'
17+
export * from './whoAmIOutput'

web/src/types/outcome.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import {
1010
UncertainScope as _UncertainScope,
1111
Scope as _Scope,
1212
Outcome as _Outcome,
13+
AchievementStatus as _AchievementStatus,
14+
OutcomeSchema as _OutcomeSchema,
1315
} from 'zod-models'
1416

15-
export type AchievementStatus = 'Achieved' | 'NotAchieved'
17+
export type AchievementStatus = _AchievementStatus
1618

1719
export type SmallTask = _SmallTask
1820
export type SmallScope = _SmallScope
@@ -36,6 +38,7 @@ export type ComputedAchievementStatus = {
3638
}
3739

3840
export type Outcome = _Outcome
41+
export const OutcomeSchema = _OutcomeSchema
3942
/*
4043
Uncertain
4144
{

web/src/types/outcomeComment.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
import { OutcomeComment as _OutcomeComment } from 'zod-models'
1+
import {
2+
OutcomeComment as _OutcomeComment,
3+
OutcomeCommentSchema as _OutcomeCommentSchema,
4+
} from 'zod-models'
25

6+
export const OutcomeCommentSchema = _OutcomeCommentSchema
37
export type OutcomeComment = _OutcomeComment

web/src/types/outcomeMember.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
import { OutcomeMember as _OutcomeMember } from 'zod-models'
1+
import {
2+
OutcomeMember as _OutcomeMember,
3+
OutcomeMemberSchema as _OutcomeMemberSchema,
4+
} from 'zod-models'
25

6+
export const OutcomeMemberSchema = _OutcomeMemberSchema
37
export type OutcomeMember = _OutcomeMember

web/src/types/projectMeta.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Profile } from './profile'
44
import { AgentPubKeyB64, CellIdString, WithActionHash } from './shared'
55
import { ProjectMetaV1 } from 'zod-models'
66

7+
export { LayeringAlgorithm } from 'zod-models'
78
export type ProjectAggregated = {
89
projectMeta: WithActionHash<ProjectMetaV1>
910
cellId: CellIdString
@@ -14,3 +15,5 @@ export type ProjectAggregated = {
1415
outcome: WithActionHash<Outcome>
1516
}[]
1617
}
18+
19+
export type ProjectMeta = ProjectMetaV1

web/src/types/tag.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import { Tag as _Tag } from 'zod-models'
1+
import { Tag as _Tag, TagSchema as _TagSchema } from 'zod-models'
22

3+
export const TagSchema = _TagSchema
34
export type Tag = _Tag

0 commit comments

Comments
 (0)