How to use TEST_TOKEN method in storybook-root

Best JavaScript code snippet using storybook-root

FacebookMessagingAPIClient.spec.ts

Source:FacebookMessagingAPIClient.spec.ts Github

copy

Full Screen

1import {Utils} from "../../src/util/Utils";2import {ATTACHMENT_TYPE} from "../../src/enums";3describe('FacebookMessagingAPIClient', () => {4 let Client: any;5 const TEST_ID = 'TEST_ID';6 const TEST_TOKEN = 'TEST_TOKEN';7 const TEST_TEXT = 'TEST_TEXT';8 const mockSendMessage = jest.fn();9 const mockGetProxyData = (data: any) => data;10 const mockUtils = {11 Utils: {12 sendMessage: mockSendMessage,13 getProxyData: mockGetProxyData,14 getRequestOptions: Utils.getRequestOptions15 }16 };17 beforeEach(() => {18 jest.mock('../../src/util/Utils', () => mockUtils);19 Client = require('../../src/client/FacebookMessagingAPIClient').FacebookMessagingAPIClient;20 });21 describe('constructor', () => {22 it('sets token and proxy', () => {23 const mockProxy = jest.fn();24 mockUtils.Utils.getProxyData = mockProxy;25 new Client(TEST_TOKEN);26 expect(mockProxy).toHaveBeenCalled();27 expect(mockProxy).toHaveBeenCalledWith({token: TEST_TOKEN}, undefined);28 mockUtils.Utils.getProxyData = mockGetProxyData;29 });30 });31 describe('markSeen', () => {32 it('send correct payload as promise given no cb', () => {33 const testClient = new Client(TEST_TOKEN);34 const EXPECTED_PAYLOAD = {"json": {"recipient": {"id": "TEST_TEXT"}, "sender_action": "mark_seen"}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};35 testClient.markSeen(TEST_TEXT);36 expect(mockSendMessage).toHaveBeenCalled();37 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);38 });39 it('send correct payload with cb given cb', () => {40 const testClient = new Client(TEST_TOKEN);41 const TEST_CB = () => TEST_TOKEN;42 const EXPECTED_PAYLOAD = {"json": {"recipient": {"id": "TEST_TEXT"}, "sender_action": "mark_seen"}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};43 testClient.markSeen(TEST_TEXT, TEST_CB);44 expect(mockSendMessage).toHaveBeenCalled();45 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);46 });47 });48 describe('toggleTyping', () => {49 it('send correct payload as promise given no cb and no toggle value - default to off', () => {50 const testClient = new Client(TEST_TOKEN);51 const EXPECTED_PAYLOAD = {"json": {"recipient": {"id": "TEST_ID"}, "sender_action": "typing_off"}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};52 testClient.toggleTyping(TEST_ID);53 expect(mockSendMessage).toHaveBeenCalled();54 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);55 });56 it('send correct payload as promise given no cb and specified value', () => {57 const testClient = new Client(TEST_TOKEN);58 const EXPECTED_PAYLOAD = {"json": {"recipient": {"id": "TEST_ID"}, "sender_action": "typing_on"}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};59 testClient.toggleTyping(TEST_ID, true);60 expect(mockSendMessage).toHaveBeenCalled();61 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);62 });63 it('send correct payload with cb given cb', () => {64 const testClient = new Client(TEST_TOKEN);65 const TEST_CB = () => TEST_TOKEN;66 const EXPECTED_PAYLOAD = {"json": {"recipient": {"id": "TEST_TEXT"}, "sender_action": "typing_on"}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};67 testClient.toggleTyping(TEST_TEXT, true, TEST_CB);68 expect(mockSendMessage).toHaveBeenCalled();69 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);70 });71 it('send correct payload with cb given cb and no value specified - using default value', () => {72 const testClient = new Client(TEST_TOKEN);73 const TEST_CB = () => TEST_TOKEN;74 const EXPECTED_PAYLOAD = {"json": {"recipient": {"id": "TEST_TEXT"}, "sender_action": "typing_off"}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};75 testClient.toggleTyping(TEST_TEXT, TEST_CB);76 expect(mockSendMessage).toHaveBeenCalled();77 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);78 });79 });80 describe('sendTextMessage', () => {81 it('send correct payload as promise given no cb', () => {82 const testClient = new Client(TEST_TOKEN);83 const EXPECTED_PAYLOAD = {"json": {"message": {"text": TEST_TEXT}, "recipient": {"id": "TEST_ID"} }, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};84 testClient.sendTextMessage(TEST_ID, TEST_TEXT);85 expect(mockSendMessage).toHaveBeenCalled();86 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);87 });88 it('send correct payload with cb given cb', () => {89 const testClient = new Client(TEST_TOKEN);90 const TEST_CB = () => TEST_TOKEN;91 const EXPECTED_PAYLOAD = {"json": {"message": {"text": TEST_TEXT}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};92 testClient.sendTextMessage(TEST_ID, TEST_TEXT, TEST_CB);93 expect(mockSendMessage).toHaveBeenCalled();94 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);95 });96 });97 describe('sendImageMessage', () => {98 it('send correct payload as promise given no cb', () => {99 const testClient = new Client(TEST_TOKEN);100 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "image"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};101 testClient.sendImageMessage(TEST_ID, TEST_TEXT);102 expect(mockSendMessage).toHaveBeenCalled();103 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);104 });105 it('send correct payload with cb given cb', () => {106 const testClient = new Client(TEST_TOKEN);107 const TEST_CB = () => TEST_TOKEN;108 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "image"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};109 testClient.sendImageMessage(TEST_ID, TEST_TEXT, TEST_CB);110 expect(mockSendMessage).toHaveBeenCalled();111 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);112 });113 });114 describe('sendAudioMessage', () => {115 it('send correct payload as promise given no cb', () => {116 const testClient = new Client(TEST_TOKEN);117 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "audio"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};118 testClient.sendAudioMessage(TEST_ID, TEST_TEXT);119 expect(mockSendMessage).toHaveBeenCalled();120 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);121 });122 it('send correct payload with cb given cb', () => {123 const testClient = new Client(TEST_TOKEN);124 const TEST_CB = () => TEST_TOKEN;125 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "audio"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};126 testClient.sendAudioMessage(TEST_ID, TEST_TEXT, TEST_CB);127 expect(mockSendMessage).toHaveBeenCalled();128 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);129 });130 });131 describe('sendVideoMessage', () => {132 it('send correct payload as promise given no cb', () => {133 const testClient = new Client(TEST_TOKEN);134 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "video"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};135 testClient.sendVideoMessage(TEST_ID, TEST_TEXT);136 expect(mockSendMessage).toHaveBeenCalled();137 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);138 });139 it('send correct payload with cb given cb', () => {140 const testClient = new Client(TEST_TOKEN);141 const TEST_CB = () => TEST_TOKEN;142 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "video"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};143 testClient.sendVideoMessage(TEST_ID, TEST_TEXT, TEST_CB);144 expect(mockSendMessage).toHaveBeenCalled();145 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);146 });147 });148 describe('sendFileMessage', () => {149 it('send correct payload as promise given no cb', () => {150 const testClient = new Client(TEST_TOKEN);151 const TEST_URL = 'http://www.testremoteurl.com/image.jpg';152 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"is_reusable": true, "url": "http://www.testremoteurl.com/image.jpg"}, "type": "file"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};153 testClient.sendFileMessage(TEST_ID, TEST_URL);154 expect(mockSendMessage).toHaveBeenCalled();155 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);156 });157 it('send correct payload with cb given cb', () => {158 const testClient = new Client(TEST_TOKEN);159 const TEST_CB = () => TEST_TOKEN;160 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"attachment_id": "TEST_TEXT"}, "type": "file"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};161 testClient.sendFileMessage(TEST_ID, TEST_TEXT, TEST_CB);162 expect(mockSendMessage).toHaveBeenCalled();163 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);164 });165 });166 describe('sendButtonsMessage', () => {167 it('send correct payload as promise given no cb', () => {168 const testClient = new Client(TEST_TOKEN);169 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"buttons": [], "template_type": "button", "text": "TEST_TEXT"}, "type": "template"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};170 testClient.sendButtonsMessage(TEST_ID, TEST_TEXT, []);171 expect(mockSendMessage).toHaveBeenCalled();172 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);173 });174 it('send correct payload with cb given cb', () => {175 const testClient = new Client(TEST_TOKEN);176 const TEST_CB = () => TEST_TOKEN;177 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"buttons": [], "template_type": "button", "text": "TEST_TEXT"}, "type": "template"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};178 testClient.sendButtonsMessage(TEST_ID, TEST_TEXT, [], TEST_CB);179 expect(mockSendMessage).toHaveBeenCalled();180 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);181 });182 });183 describe('sendTemplateMessage', () => {184 it('send correct payload as promise given no cb', () => {185 const testClient = new Client(TEST_TOKEN);186 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": "TEST_TEXT", "type": "template"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};187 testClient.sendTemplateMessage(TEST_ID, TEST_TEXT);188 expect(mockSendMessage).toHaveBeenCalled();189 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);190 });191 it('send correct payload with cb given cb', () => {192 const testClient = new Client(TEST_TOKEN);193 const TEST_CB = () => TEST_TOKEN;194 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": "TEST_TEXT", "type": "template"}}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};195 testClient.sendTemplateMessage(TEST_ID, TEST_TEXT, TEST_CB);196 expect(mockSendMessage).toHaveBeenCalled();197 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);198 });199 });200 describe('sendQuickReplyMessage', () => {201 it('send correct payload as promise given no cb', () => {202 const testClient = new Client(TEST_TOKEN);203 const EXPECTED_PAYLOAD = {"json": {"message": {"attachment": {"payload": {"test": "TEST_TEXT"}, "type": "template"}, "quick_replies": []}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};204 testClient.sendQuickReplyMessage(TEST_ID, {type: ATTACHMENT_TYPE.TEMPLATE,payload: {test:TEST_TEXT}}, []);205 expect(mockSendMessage).toHaveBeenCalled();206 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);207 });208 it('send correct payload with cb given cb', () => {209 const testClient = new Client(TEST_TOKEN);210 const TEST_CB = () => TEST_TOKEN;211 const EXPECTED_PAYLOAD = {"json": {"message": {"quick_replies": [], "text": "TEST_TEXT"}, "recipient": {"id": "TEST_ID"}}, "method": "POST", "qs": {}, "url": "https://graph.facebook.com/v3.1/me/messages"};212 testClient.sendQuickReplyMessage(TEST_ID, TEST_TEXT, [], TEST_CB);213 expect(mockSendMessage).toHaveBeenCalled();214 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);215 });216 });217 describe('getUserProfile', () => {218 it('send correct default payload as promise given incorrect fieldsArray parameter', () => {219 const testClient = new Client(TEST_TOKEN);220 const EXPECTED_PAYLOAD = {"method": "GET", "qs": {"fields": "first_name"}, "url": "https://graph.facebook.com/v3.1/TEST_ID"};221 testClient.getUserProfile(TEST_ID, TEST_TEXT);222 expect(mockSendMessage).toHaveBeenCalled();223 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, undefined);224 });225 it('send correct payload with cb given cb and correct payload parameter', () => {226 const testClient = new Client(TEST_TOKEN);227 const TEST_CB = () => TEST_TOKEN;228 const EXPECTED_PAYLOAD = {"method": "GET", "qs": {"fields": "first_name,last_name,birth_date"}, "url": "https://graph.facebook.com/v3.1/TEST_ID"};229 testClient.getUserProfile(TEST_ID,['first_name', 'last_name', 'birth_date'], TEST_CB);230 expect(mockSendMessage).toHaveBeenCalled();231 expect(mockSendMessage).toHaveBeenCalledWith(EXPECTED_PAYLOAD, {token: TEST_TOKEN}, TEST_CB);232 });233 });...

Full Screen

Full Screen

agent.spec.ts

Source:agent.spec.ts Github

copy

Full Screen

1import { BigNumber } from "bignumber.js";2import { Interface } from "ethers/lib/utils";3import { FindingType, FindingSeverity, Finding, HandleTransaction, Network, ethers } from "forta-agent";4import { createAddress, MockEthersProvider, TestTransactionEvent } from "forta-agent-tools/lib/tests";5import { provideHandleTransaction } from "./agent";6import BalanceFetcher from "./balance.fetcher";7import { TOKEN_ABI, EVENT } from "./constants";8import { AgentConfig, NetworkData, toBn } from "./utils";9import { NetworkManager } from "forta-agent-tools";10const VAULT_IFACE = new Interface(EVENT);11const IRRELEVANT_IFACE = new ethers.utils.Interface(["event Event()"]);12const VAULT_ADDRESS = createAddress("0x1");13const createFinding = (14 user: string,15 token: string,16 delta: ethers.BigNumberish,17 percentage: BigNumber,18 symbol: string19) => {20 let action, alertId;21 if (ethers.BigNumber.from(delta).isNegative()) {22 action = "withdrawal";23 alertId = "BAL-2-1";24 } else {25 action = "deposit";26 alertId = "BAL-2-2";27 }28 return Finding.fromObject({29 name: `Large ${symbol} internal balance ${action}`,30 description: `User's (${user}) internal balance of ${symbol} has changed with large ${symbol} ${action} (${percentage31 .decimalPlaces(3)32 .toString(10)}% of Vault's ${symbol} balance)`,33 alertId,34 protocol: "Balancer",35 severity: FindingSeverity.Info,36 type: FindingType.Info,37 metadata: {38 user: user.toLowerCase(),39 token: token.toLowerCase(),40 delta: delta.toString(),41 percentage: percentage.toString(10),42 },43 });44};45const DEFAULT_CONFIG: AgentConfig = {46 [Network.MAINNET]: {47 vaultAddress: VAULT_ADDRESS,48 threshold: "10",49 },50};51describe("Large internal balance deposits/withdrawals", () => {52 let provider: ethers.providers.Provider;53 let mockProvider: MockEthersProvider;54 let mockBalanceFetcher: BalanceFetcher;55 let networkManager: NetworkManager<NetworkData>;56 let handleTransaction: HandleTransaction;57 const TEST_TOKEN = createAddress("0x2");58 const TEST_BALANCE = ethers.BigNumber.from("1000");59 const TEST_SYMBOL = "NETH";60 const TEST_BLOCK = 123;61 beforeEach(() => {62 mockProvider = new MockEthersProvider();63 provider = mockProvider as unknown as ethers.providers.Provider;64 mockProvider.addCallTo(TEST_TOKEN, TEST_BLOCK - 1, new Interface(TOKEN_ABI), "balanceOf", {65 inputs: [VAULT_ADDRESS],66 outputs: [TEST_BALANCE],67 });68 mockProvider.addCallTo(TEST_TOKEN, TEST_BLOCK - 1, new Interface(TOKEN_ABI), "symbol", {69 inputs: [],70 outputs: [TEST_SYMBOL],71 });72 networkManager = new NetworkManager(DEFAULT_CONFIG, Network.MAINNET);73 mockBalanceFetcher = new BalanceFetcher(mockProvider as any);74 handleTransaction = provideHandleTransaction(networkManager, mockBalanceFetcher);75 });76 it("returns empty findings for empty transactions", async () => {77 const txEvent = new TestTransactionEvent();78 const findings: Finding[] = await handleTransaction(txEvent);79 expect(findings).toStrictEqual([]);80 });81 it("should ignore target events emitted from another contract", async () => {82 const txEvent = new TestTransactionEvent()83 .setBlock(TEST_BLOCK)84 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), createAddress("0x2"), [85 createAddress("0x3"),86 TEST_TOKEN,87 "120",88 ]);89 expect(await handleTransaction(txEvent)).toStrictEqual([]);90 expect(mockProvider.call).toHaveBeenCalledTimes(0);91 });92 it("should ignore other events emitted from target contract", async () => {93 const txEvent = new TestTransactionEvent().addInterfaceEventLog(94 IRRELEVANT_IFACE.getEvent("Event"),95 VAULT_ADDRESS,96 []97 );98 expect(await handleTransaction(txEvent)).toStrictEqual([]);99 expect(mockProvider.call).toHaveBeenCalledTimes(0);100 });101 it("should not return a finding for a deposit that is not large", async () => {102 const txEvent = new TestTransactionEvent()103 .setBlock(TEST_BLOCK)104 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [105 createAddress("0x3"),106 TEST_TOKEN,107 "90",108 ]);109 expect(await handleTransaction(txEvent)).toStrictEqual([]);110 expect(mockProvider.call).toHaveBeenCalledTimes(1);111 });112 it("should not return a finding for a withdrawal that is not large", async () => {113 const txEvent = new TestTransactionEvent()114 .setBlock(TEST_BLOCK)115 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [116 createAddress("0x3"),117 TEST_TOKEN,118 "-90",119 ]);120 expect(await handleTransaction(txEvent)).toStrictEqual([]);121 expect(mockProvider.call).toHaveBeenCalledTimes(1);122 });123 it("returns findings if there are deposits with a large amount", async () => {124 const txEvent = new TestTransactionEvent()125 .setBlock(TEST_BLOCK)126 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [127 createAddress("0x3"),128 TEST_TOKEN,129 "120",130 ])131 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [132 createAddress("0x4"),133 TEST_TOKEN,134 "110",135 ]);136 const findings: Finding[] = await handleTransaction(txEvent);137 const percentage1 = new BigNumber(120 * 100).dividedBy(toBn(TEST_BALANCE));138 const percentage2 = new BigNumber(110 * 100).dividedBy(toBn(TEST_BALANCE));139 expect(findings).toStrictEqual([140 createFinding(createAddress("0x3"), TEST_TOKEN, "120", percentage1, TEST_SYMBOL),141 createFinding(createAddress("0x4"), TEST_TOKEN, "110", percentage2, TEST_SYMBOL),142 ]);143 expect(mockProvider.call).toHaveBeenCalledTimes(4);144 });145 it("returns findings if there are withdrawals with a large amount", async () => {146 const txEvent = new TestTransactionEvent()147 .setBlock(TEST_BLOCK)148 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [149 createAddress("0x3"),150 TEST_TOKEN,151 "-120",152 ])153 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [154 createAddress("0x4"),155 TEST_TOKEN,156 "-110",157 ]);158 const findings: Finding[] = await handleTransaction(txEvent);159 const percentage1 = new BigNumber(120 * 100).dividedBy(toBn(TEST_BALANCE));160 const percentage2 = new BigNumber(110 * 100).dividedBy(toBn(TEST_BALANCE));161 expect(findings).toStrictEqual([162 createFinding(createAddress("0x3"), TEST_TOKEN, "-120", percentage1, TEST_SYMBOL),163 createFinding(createAddress("0x4"), TEST_TOKEN, "-110", percentage2, TEST_SYMBOL),164 ]);165 expect(mockProvider.call).toHaveBeenCalledTimes(4);166 });167 it("returns findings if there are withdrawals and deposits with large amounts", async () => {168 const txEvent = new TestTransactionEvent()169 .setBlock(TEST_BLOCK)170 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [171 createAddress("0x3"),172 TEST_TOKEN,173 "120",174 ])175 .addInterfaceEventLog(VAULT_IFACE.getEvent("InternalBalanceChanged"), VAULT_ADDRESS, [176 createAddress("0x4"),177 TEST_TOKEN,178 "-110",179 ]);180 const findings: Finding[] = await handleTransaction(txEvent);181 const percentage1 = new BigNumber(120 * 100).dividedBy(toBn(TEST_BALANCE));182 const percentage2 = new BigNumber(110 * 100).dividedBy(toBn(TEST_BALANCE));183 expect(findings).toStrictEqual([184 createFinding(createAddress("0x3"), TEST_TOKEN, "120", percentage1, TEST_SYMBOL),185 createFinding(createAddress("0x4"), TEST_TOKEN, "-110", percentage2, TEST_SYMBOL),186 ]);187 expect(mockProvider.call).toHaveBeenCalledTimes(4);188 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const admin = require('firebase-admin');2const functions = require('firebase-functions');3const serviceAccount = require("./serviceAccountKey.json");4admin.initializeApp({5 credential: admin.credential.cert(serviceAccount),6 databaseURL: "https://ssafy-245804.firebaseio.com"7});8var db = admin.firestore();9exports.dbPostWrite = functions.firestore.document('posts/{any}').onCreate( event => {10 const payload = {11 notification : {12 title: '포스트 생성되었습니다',13 body: '알림아 울려줘'14 }15 }16 console.log('글변경')17 db.collection('users').get().then((snapshot)=> {18 snapshot.forEach(doc => {19 if (doc.data()['test_token'] !='' && doc.data()['test_token'] != undefined) {20 console.log(doc.data()['test_token'])21 admin.messaging().sendToDevice(doc.data()['test_token'], payload)22 }23 })24 })25 });26exports.dbBoardWrite = functions.firestore.document('boards/{any}').onCreate( event => {27 const payload = {28 notification : {29 title: '게시글 생성되었습니다',30 body: '알림아 울려줘'31 }32 }33 console.log('글변경')34 db.collection('users').get().then((snapshot)=> {35 snapshot.forEach(doc => {36 if (doc.data()['test_token'] !='' && doc.data()['test_token'] != undefined) {37 console.log(doc.data()['test_token'])38 admin.messaging().sendToDevice(doc.data()['test_token'], payload)39 }40 })41 })42 });43 exports.dbPostWriteComment = functions.firestore.document('posts/{any}/post-comments/{anyy}').onCreate( event => {44 const payload = {45 notification : {46 title: '포스트게시글에 댓글 생성되었습니다',47 body: '알림아 울려줘'48 }49 }50 console.log('댓글생성')51 db.collection('users').get().then((snapshot)=> {52 snapshot.forEach(doc => {53 if (doc.data()['userClass'] == 'admin' && doc.data()['test_token']) {54 console.log(doc.data()['test_token'])55 admin.messaging().sendToDevice(doc.data()['test_token'], payload)56 }57 })58 })59 });60 exports.dbBoardWriteComment = functions.firestore.document('boards/{any}/post-comments/{anyy}').onCreate( event => {61 const payload = {62 notification : {63 title: '게시글에 댓글 생성되었습니다',64 body: '알림아 울려줘'65 }66 }67 console.log('댓글생성')68 db.collection('users').get().then((snapshot)=> {69 snapshot.forEach(doc => {70 71 if (doc.data()['userClass'] == 'admin' && doc.data()['test_token']) {72 console.log(doc.data()['test_token'])73 admin.messaging().sendToDevice(doc.data()['test_token'], payload)74 }75 })76 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybookRoot = require('storybook-root');2storybookRoot.TEST_TOKEN();3var storybookRoot = require('storybook-root');4storybookRoot.TEST_TOKEN();5var storybookRoot = require('storybook-root');6storybookRoot.TEST_TOKEN();7var storybookRoot = require('storybook-root');8storybookRoot.TEST_TOKEN();9var storybookRoot = require('storybook-root');10storybookRoot.TEST_TOKEN();11var storybookRoot = require('storybook-root');12storybookRoot.TEST_TOKEN();13var storybookRoot = require('storybook-root');14storybookRoot.TEST_TOKEN();15var storybookRoot = require('storybook-root');16storybookRoot.TEST_TOKEN();17var storybookRoot = require('storybook-root');18storybookRoot.TEST_TOKEN();19var storybookRoot = require('storybook-root');20storybookRoot.TEST_TOKEN();21var storybookRoot = require('storybook-root');22storybookRoot.TEST_TOKEN();23var storybookRoot = require('storybook-root');24storybookRoot.TEST_TOKEN();25var storybookRoot = require('storybook-root');26storybookRoot.TEST_TOKEN();27var storybookRoot = require('storybook-root');28storybookRoot.TEST_TOKEN();29var storybookRoot = require('storybook-root');30storybookRoot.TEST_TOKEN();

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs';4import { withInfo } from '@storybook/addon-info';5import { withTests } from '@storybook/addon-jest';6import results from '../.jest-test-results.json';7import Button from '../src/components/Button';8storiesOf('Button', module)9 .addDecorator(withKnobs)10 .addDecorator(withInfo)11 .addDecorator(12 withTests({13 })14 .add(15 () => (16 <Button onClick={action('clicked')}>17 {text('Label', 'Hello Storybook')}18 { jest: 'Button' }19 );

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2storybookRoot.testToken();3const storybookRoot = require('storybook-root');4storybookRoot.testToken();5const storybookRoot = require('storybook-root');6storybookRoot.testToken();7const storybookRoot = require('storybook-root');8storybookRoot.testToken();9const storybookRoot = require('storybook-root');10storybookRoot.testToken();11const storybookRoot = require('storybook-root');12storybookRoot.testToken();13const storybookRoot = require('storybook-root');14storybookRoot.testToken();15const storybookRoot = require('storybook-root');16storybookRoot.testToken();17const storybookRoot = require('storybook-root');18storybookRoot.testToken();19const storybookRoot = require('storybook-root');20storybookRoot.testToken();21const storybookRoot = require('storybook-root');22storybookRoot.testToken();23const storybookRoot = require('storybook-root');24storybookRoot.testToken();25const storybookRoot = require('storybook-root');26storybookRoot.testToken();27const storybookRoot = require('storybook-root');28storybookRoot.testToken();29const storybookRoot = require('storybook-root');30storybookRoot.testToken();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { TEST_TOKEN } = require('storybook-root');2console.log(TEST_TOKEN);3const { TEST_TOKEN } = require('storybook-root');4console.log(TEST_TOKEN);5const { TEST_TOKEN } = require('storybook-root');6console.log(TEST_TOKEN);7const { TEST_TOKEN } = require('storybook-root');8console.log(TEST_TOKEN);9const { TEST_TOKEN } = require('storybook-root');10console.log(TEST_TOKEN);11const { TEST_TOKEN } = require('storybook-root');12console.log(TEST_TOKEN);13const { TEST_TOKEN } = require('storybook-root');14console.log(TEST_TOKEN);15const { TEST_TOKEN } = require('storybook-root');16console.log(TEST_TOKEN);17const { TEST_TOKEN } = require('storybook-root');18console.log(TEST_TOKEN);19const { TEST_TOKEN } = require('storybook-root');20console.log(TEST_TOKEN);21const { TEST_TOKEN } = require('storybook-root');22console.log(TEST_TOKEN);23const { TEST_TOKEN } = require('storybook-root');24console.log(TEST_TOKEN);25const { TEST_TOKEN } = require('storybook-root');26console.log(TEST_TOKEN);

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('test');2test();3const storybook = require('storybook-root');4module.exports = () => {5 storybook();6}7const storybook = require('storybook');8module.exports = () => {9 storybook();10}11const test = require('test');12module.exports = () => {13 test();14}15const storybook = require('storybook-root');16module.exports = () => {17 storybook();18}19const storybook = require('storybook');20module.exports = () => {21 storybook();22}23const test = require('test');24module.exports = () => {25 test();26}27const storybook = require('storybook-root');28module.exports = () => {29 storybook();30}31const storybook = require('storybook');32module.exports = () => {33 storybook();34}35const test = require('test');36module.exports = () => {37 test();38}39const storybook = require('storybook-root');40module.exports = () => {41 storybook();42}43const storybook = require('storybook');44module.exports = () => {45 storybook();46}47const test = require('test');48module.exports = () => {49 test();50}51const storybook = require('storybook-root');52module.exports = () => {53 storybook();54}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful