···11+---
22+date: 2026-02-15T15:01:43.100Z
33+description: Getting my third test file
44+slug: file-three
55+tags:
66+ - ATProto
77+ - ATmosphere
88+ - decentralization
99+title: Testing 3 - some good functions
1010+---
1111+1212+## Test file information
1313+1414+This is another test file.
+14
__tests__/markdowns/file-two.md
···11+---
22+date: 2026-02-15T15:01:43.100Z
33+description: Getting my second test file
44+slug: file-two
55+tags:
66+ - ATProto
77+ - ATmosphere
88+ - decentralization
99+title: Testing 2 - some good functions
1010+---
1111+1212+## Test file information
1313+1414+This is another test file.
+143-48
__tests__/processMarkdown.test.ts
···11-import { expect, test } from 'vitest'
22-import { getMarkdownFile, setMarkdownFile } from '../src/processMarkdown'
11+import { expect, test, describe } from 'vitest'
22+import { getMarkdownFile, setMarkdownFile, addDataToMarkdownFile } from '../src/processMarkdown'
3344-test('get markdown file and its data', async () => {
55- const fullFilePath = './__tests__/markdowns/file.md';
66- const result = getMarkdownFile(fullFilePath);
77- expect(result).toHaveProperty('data');
88- expect(result).toHaveProperty('content');
99- expect(result).toHaveProperty('fileName');
1010- expect(result).toHaveProperty('pathToFile');
1111- expect(result.fileName).toBe('file');
1212- expect(result.pathToFile).toBe('./__tests__/markdowns');
1313- expect(result.data).toEqual({
1414- "date": new Date("2026-02-15T15:01:43.100Z"),
1515- "description": "Getting my test file",
1616- "slug": "file",
1717- "tags": [
1818- "ATProto",
1919- "ATmosphere",
2020- "decentralization",
2121- ],
2222- "title": "Testing - some good functions",
2323- });
2424- expect(result.content).toBe(`
44+describe('Handle reading markdown files', () => {
55+ test('get markdown file and its data', async () => {
66+ const fullFilePath = './__tests__/markdowns/file.md';
77+ const result = getMarkdownFile(fullFilePath);
88+ expect(result).toHaveProperty('data');
99+ expect(result).toHaveProperty('content');
1010+ expect(result).toHaveProperty('fileName');
1111+ expect(result).toHaveProperty('pathToFile');
1212+ expect(result.fileName).toBe('file');
1313+ expect(result.pathToFile).toBe('./__tests__/markdowns');
1414+ expect(result.data).toEqual({
1515+ "date": new Date("2026-02-15T15:01:43.100Z"),
1616+ "description": "Getting my test file",
1717+ "slug": "file",
1818+ "tags": [
1919+ "ATProto",
2020+ "ATmosphere",
2121+ "decentralization",
2222+ ],
2323+ "title": "Testing - some good functions",
2424+ });
2525+ expect(result.content).toBe(`
2526## Test file information
26272728This is a test file.
2829`);
3030+ });
2931});
30323131-test('set markdown file and its data with no change', async () => {
3232- const fullFilePath = './__tests__/markdowns/file.md';
3333- const { data, content, fileName, pathToFile } = getMarkdownFile(fullFilePath);
3434- const markdownFileSet = setMarkdownFile(pathToFile, 'title', 'content',
3535- { slug: fileName, ...data, content } );
3333+describe('Handle changing markdown files', () => {
3434+ test('set markdown file and its data with no change', async () => {
3535+ const fullFilePath = './__tests__/markdowns/file-two.md';
3636+ const { data, content, fileName, pathToFile } = getMarkdownFile(fullFilePath);
3737+ const markdownFileSet = setMarkdownFile(pathToFile, 'title', 'content',
3838+ { slug: fileName, ...data, content } );
36393737- expect(markdownFileSet).toBe(true);
3838- const result = getMarkdownFile(fullFilePath);
4040+ expect(markdownFileSet).toBe(true);
4141+ const result = getMarkdownFile(fullFilePath);
39424040- expect(result).toHaveProperty('data');
4141- expect(result).toHaveProperty('content');
4242- expect(result).toHaveProperty('fileName');
4343- expect(result).toHaveProperty('pathToFile');
4444- expect(result.fileName).toBe('file');
4545- expect(result.pathToFile).toBe('./__tests__/markdowns');
4646- expect(result.data).toEqual({
4747- "date": new Date("2026-02-15T15:01:43.100Z"),
4848- "description": "Getting my test file",
4949- "tags": [
5050- "ATProto",
5151- "ATmosphere",
5252- "decentralization",
5353- ],
5454- "title": "Testing - some good functions",
5555- "slug": "file"
4343+ expect(result).toHaveProperty('data');
4444+ expect(result).toHaveProperty('content');
4545+ expect(result).toHaveProperty('fileName');
4646+ expect(result).toHaveProperty('pathToFile');
4747+ expect(result.fileName).toBe('file-two');
4848+ expect(result.pathToFile).toBe('./__tests__/markdowns');
4949+ expect(result.data).toEqual({
5050+ "date": new Date("2026-02-15T15:01:43.100Z"),
5151+ "description": "Getting my second test file",
5252+ "tags": [
5353+ "ATProto",
5454+ "ATmosphere",
5555+ "decentralization",
5656+ ],
5757+ "title": "Testing 2 - some good functions",
5858+ "slug": "file-two"
5959+ });
6060+ expect(result.content).toBe(`
6161+## Test file information
6262+6363+This is another test file.
6464+`);
5665 });
5757- expect(result.content).toBe(`
6666+6767+ test('set markdown file and its data with change', async () => {
6868+ const fullFilePath = './__tests__/markdowns/file-three.md';
6969+ const { data, content, fileName, pathToFile } = getMarkdownFile(fullFilePath);
7070+7171+ const result = getMarkdownFile(fullFilePath);
7272+7373+ expect(result).toHaveProperty('data');
7474+ expect(result).toHaveProperty('content');
7575+ expect(result).toHaveProperty('fileName');
7676+ expect(result).toHaveProperty('pathToFile');
7777+ expect(result.fileName).toBe('file-three');
7878+ expect(result.pathToFile).toBe('./__tests__/markdowns');
7979+ expect(result.data).toEqual({
8080+ "date": new Date("2026-02-15T15:01:43.100Z"),
8181+ "description": "Getting my third test file",
8282+ "tags": [
8383+ "ATProto",
8484+ "ATmosphere",
8585+ "decentralization",
8686+ ],
8787+ "title": "Testing 3 - some good functions",
8888+ "slug": "file-three"
8989+ });
9090+ expect(result.content).toBe(`
5891## Test file information
59926060-This is a test file.
9393+This is another test file.
6194`);
9595+ const markdownFileSet = addDataToMarkdownFile(fullFilePath, 'title', 'content',
9696+ { newData: "foobar" } );
9797+9898+ expect(markdownFileSet).toBe(true);
9999+100100+ const resultTwo = getMarkdownFile(fullFilePath);
101101+102102+ expect(resultTwo).toHaveProperty('data');
103103+ expect(resultTwo).toHaveProperty('content');
104104+ expect(resultTwo).toHaveProperty('fileName');
105105+ expect(resultTwo).toHaveProperty('pathToFile');
106106+ expect(resultTwo.fileName).toBe('file-three');
107107+ expect(resultTwo.pathToFile).toBe('./__tests__/markdowns');
108108+ expect(resultTwo.data).toEqual({
109109+ "date": new Date("2026-02-15T15:01:43.100Z"),
110110+ "description": "Getting my third test file",
111111+ "tags": [
112112+ "ATProto",
113113+ "ATmosphere",
114114+ "decentralization",
115115+ ],
116116+ "title": "Testing 3 - some good functions",
117117+ "slug": "file-three",
118118+ "newData": "foobar"
119119+ });
120120+ expect(resultTwo.content).toBe(`
121121+## Test file information
122122+123123+This is another test file.
124124+`);
125125+ const markdownFileSetTwo = setMarkdownFile(pathToFile, 'title', 'content',
126126+ { slug: fileName, ...data, content }, true );
127127+128128+ expect(markdownFileSetTwo).toBe(true);
129129+ const resultThree = getMarkdownFile(fullFilePath);
130130+131131+ expect({ slug: fileName, ...data, content }).not.toHaveProperty('newData');
132132+ expect(resultThree).toHaveProperty('data');
133133+ expect(resultThree).toHaveProperty('content');
134134+ expect(resultThree).toHaveProperty('fileName');
135135+ expect(resultThree).toHaveProperty('pathToFile');
136136+ expect(resultThree.fileName).toBe('file-three');
137137+ expect(resultThree.pathToFile).toBe('./__tests__/markdowns');
138138+ expect(resultThree.data).toEqual({
139139+ "date": new Date("2026-02-15T15:01:43.100Z"),
140140+ "description": "Getting my third test file",
141141+ "tags": [
142142+ "ATProto",
143143+ "ATmosphere",
144144+ "decentralization",
145145+ ],
146146+ "title": "Testing 3 - some good functions",
147147+ "slug": "file-three"
148148+ });
149149+ expect(resultThree.content).toBe(`
150150+## Test file information
151151+152152+This is another test file.
153153+`);
154154+ });
155155+156156+62157});
···129129 console.log(`Uploaded record with rkey: ${rKey}`, resultRecord);
130130 return {rKey, resultRecord};
131131};
132132-133133-134134-// Main execution function - can be called when running this file directly
135135-export const main = async () => {
136136- const config = setUpEnv();
137137- if (!config) return;
138138- const { rpc, manager } = await connectionManager(config);
139139- const { handle } = config;
140140-141141- //reversedHandle to make a fun example lexicon
142142- const reversedHandle = handle.split('.').reverse().map(word => word).join('.');
143143- //An activity here is like a workout. running, walking, lifting weights, etc.
144144- const collection = `${reversedHandle}.feed.activity`
145145-146146- //A list of activities that may be gotten from your phone or wherever, but you get the whole list everytime
147147- let activities = []
148148-149149- // Helper function to upload activities
150150- const uploadActivities = async (activities: any[], handle: string, collection: string, rpc: Client) => {
151151- for (const activity of activities) {
152152- //Creates that unique key from the startTime of the activity so we don't have duplicates
153153- let rKey = TID.create(activity.startTime.getTime() * 1000, CLOCK_ID);
154154-155155- await ok(rpc.post('com.atproto.repo.putRecord', {
156156- input: {
157157- repo: handle,
158158- collection,
159159- rkey: rKey,
160160- record: activity,
161161- }
162162- }));
163163- console.log(`Uploaded activity with rkey: ${rKey}`);
164164- }
165165- }
166166-167167- //I just finished a run, it's saved to my phone, now uploading it to the PDS
168168- activities.push({
169169- $type: collection,
170170- type: 'run',
171171- startTime: new Date()
172172- })
173173-174174- console.log('You just finished a run. Uploading it to the PDS.');
175175-176176- //Upload my activities
177177- await uploadActivities(activities, handle, collection, rpc);
178178-179179- //Going to generate the key here to show you can find the record from it easily if you have a date
180180- const rkey = TID.create(activities[0].startTime.getTime() * 1000, CLOCK_ID);
181181-182182- const activityFromPDS = await ok((rpc as any).get('com.atproto.repo.getRecord', {
183183- params: {
184184- repo: handle,
185185- collection,
186186- rkey,
187187- }
188188- })) as any;
189189-190190- console.log(`The PDS shows you went on a ${activityFromPDS.value.type} at ${activityFromPDS.value.startTime.toLocaleString()}.`);
191191-192192- //I decide I want to go on a walk later, so I add it to the list
193193- activities.push({
194194- $type: collection,
195195- type: 'walk',
196196- startTime: new Date()
197197- })
198198-199199- console.log('You just finished a walk. Uploading it to the PDS.');
200200-201201- //upload the new activities so the newest one can sync
202202- await uploadActivities(activities, handle, collection, rpc);
203203-204204- const listResult = await ok((rpc as any).get('com.atproto.repo.listRecords', {
205205- params: {
206206- repo: handle,
207207- collection,
208208- limit: 10,
209209- }
210210- })) as any;
211211-212212- console.log("Since you did an upsert you should only have 2 records even tho you uploaded 3.")
213213- console.log(`You have ${listResult.records.length} activities saved in the PDS.`);
214214- for (const recordIndex in listResult.records){
215215- const record = listResult.records[recordIndex]
216216- console.log(`The PDS shows you went on a ${record.value.type} at ${record.value.startTime.toLocaleString()}.`);
217217- }
218218-};
219219-220220-// Run main function if this file is executed directly
221221-//if (require.main === module) {
222222-// main().catch(console.error);
223223-//}