feat: Add connection serializer
This commit is contained in:
16
packages/backend/src/serializers/connection.js
Normal file
16
packages/backend/src/serializers/connection.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const connectionSerializer = (connection) => {
|
||||||
|
return {
|
||||||
|
id: connection.id,
|
||||||
|
key: connection.key,
|
||||||
|
reconnectable: connection.reconnectable,
|
||||||
|
appAuthClientId: connection.appAuthClientId,
|
||||||
|
formattedData: {
|
||||||
|
screenName: connection.formattedData.screenName,
|
||||||
|
},
|
||||||
|
verified: connection.verified,
|
||||||
|
createdAt: connection.createdAt.getTime(),
|
||||||
|
updatedAt: connection.updatedAt.getTime(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connectionSerializer;
|
28
packages/backend/src/serializers/connection.test.js
Normal file
28
packages/backend/src/serializers/connection.test.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import { createConnection } from '../../test/factories/connection';
|
||||||
|
import connectionSerializer from './connection';
|
||||||
|
|
||||||
|
describe('connectionSerializer', () => {
|
||||||
|
let connection;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
connection = await createConnection();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return connection data', async () => {
|
||||||
|
const expectedPayload = {
|
||||||
|
id: connection.id,
|
||||||
|
key: connection.key,
|
||||||
|
reconnectable: connection.reconnectable,
|
||||||
|
appAuthClientId: connection.appAuthClientId,
|
||||||
|
formattedData: {
|
||||||
|
screenName: connection.formattedData.screenName,
|
||||||
|
},
|
||||||
|
verified: connection.verified,
|
||||||
|
createdAt: connection.createdAt.getTime(),
|
||||||
|
updatedAt: connection.updatedAt.getTime(),
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(connectionSerializer(connection)).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -6,6 +6,7 @@ import appAuthClientSerializer from './app-auth-client.js';
|
|||||||
import appConfigSerializer from './app-config.js';
|
import appConfigSerializer from './app-config.js';
|
||||||
import flowSerializer from './flow.js';
|
import flowSerializer from './flow.js';
|
||||||
import stepSerializer from './step.js';
|
import stepSerializer from './step.js';
|
||||||
|
import connectionSerializer from './connection.js';
|
||||||
import appSerializer from './app.js';
|
import appSerializer from './app.js';
|
||||||
import authSerializer from './auth.js';
|
import authSerializer from './auth.js';
|
||||||
import triggerSerializer from './trigger.js';
|
import triggerSerializer from './trigger.js';
|
||||||
@@ -23,6 +24,7 @@ const serializers = {
|
|||||||
AppConfig: appConfigSerializer,
|
AppConfig: appConfigSerializer,
|
||||||
Flow: flowSerializer,
|
Flow: flowSerializer,
|
||||||
Step: stepSerializer,
|
Step: stepSerializer,
|
||||||
|
Connection: connectionSerializer,
|
||||||
App: appSerializer,
|
App: appSerializer,
|
||||||
Auth: authSerializer,
|
Auth: authSerializer,
|
||||||
Trigger: triggerSerializer,
|
Trigger: triggerSerializer,
|
||||||
|
Reference in New Issue
Block a user